Rails 3,安装pg gem时出错

时间:2013-05-25 20:14:01

标签: ruby-on-rails pg

试图安装pg gem我得到了下一个错误:

alex@ubuntu:~/RubymineProjects/Tiger Skills$ gem install pg
ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /var/lib/gems/1.9.1 directory.
alex@ubuntu:~/RubymineProjects/Tiger Skills$ sudo gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    /usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:2:in `<main>'


Gem files will remain installed in /var/lib/gems/1.9.1/gems/pg-0.15.1 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/pg-0.15.1/ext/gem_make.out

gem_make.out文件:

/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:2:in `<main>'

已经尝试使用

解决
$ sudo apt-get install postgresql-client libpq5 libpq-dev

然后:

$ sudo gem install pg

4 个答案:

答案 0 :(得分:1)

那是因为您没有为目录设置写入权限,请尝试:

   chmod +777 /var/lib/gems/1.9.1

答案 1 :(得分:1)

这有助于我:

sudo apt-get install rails 

答案 2 :(得分:0)

您需要安装Ruby包的-dev部分。类似的东西:

sudo apt-get install ruby1.9-dev

应该为您提供编译二进制扩展所需的Ruby部分。

祝你好运!

答案 3 :(得分:0)

我遇到了几乎相同的问题 我用它来解决它。

$rvmsudo gem install pg