问题
I'm having a devil of a time installing Nokogiri on Ubuntu 12.04. I use rbenv.
$ gem install nokogiri -v '1.6.1'
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.1/.autotest
$ sudo gem install nokogiri -v '1.6.1'
ERROR: Error installing nokogiri:
nokogiri requires Ruby version >= 1.9.2.
$ rbenv sudo gem install nokogiri -v '1.6.1'
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/home/deploy/.rbenv/versions/2.0.0-p353/bin/ruby extconf.rb
Gem files will remain installed in /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.1 for inspection.
Results logged to /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.1/ext/nokogiri/gem_make.out
$ ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
$ sudo ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
$ rbenv sudo ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
$ echo $PATH
/home/deploy/.rbenv/bin:/home/deploy/.rbenv/bin:/home/deploy/.rbenv/shims:/home/deploy/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
It seems like I need some way of having sudo ruby -v
give me 2.0.0
. What am I missing?
回答1:
You shouldn't need sudo
when you do gem install
with rbenv. Unfortunately, the ownership is usually not correct for the .rbenv directory on a new install.
Do this first to set your permissions correctly:
sudo chown -R $USER "$HOME/.rbenv"
Then go ahead and just run the install again:
gem install nokogiri -v '1.6.1'
It should work without sudo
.
回答2:
This works fine, but make sure to restart your terminal window after running sudo chown.
sudo chown -R $USER "$HOME/.rbenv"
# close terminal, then run the gem install
gem install nokogiri
来源:https://stackoverflow.com/questions/21371459/why-doesnt-nokogiri-install