如何获得写入Ubuntu中gem目录的权限?

时间:2015-09-21 16:56:38

标签: ruby-on-rails ruby linux ubuntu

我试图在Ruby on Rails中构建我的第一个应用程序,但是当我运行bundle install时,我收到此消息:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

   /usr/bin/ruby2.1 -r ./siteconf20150921-23095-eac5m6.rb extconf.rb  checking if the C compiler accepts ... yes Building nokogiri using
packaged libraries. checking for gzdopen() in -lz... no zlib is
missing; necessary for building libxml2
*** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers.  Check
the mkmf.log file for more details.  You may need configuration
options.

Provided configuration options:     --with-opt-dir  --without-opt-dir
--with-opt-include  --without-opt-include=${opt-dir}/include
--with-opt-lib  --without-opt-lib=${opt-dir}/lib    --with-make-prog
--without-make-prog     --srcdir=.  --curdir    --ruby=/usr/bin/ruby2.1
--help  --clean     --use-system-libraries  --enable-static
--disable-static    --with-zlib-dir     --without-zlib-dir
--with-zlib-include     --without-zlib-include=${zlib-dir}/include
--with-zlib-lib     --without-zlib-lib=${zlib-dir}/lib
--enable-cross-build    --disable-cross-build

extconf failed, exit code 1

Gem files will remain installed in
/tmp/bundler20150921-23095-1bpxdrp/nokogiri-1.6.6.2/gems/nokogiri-1.6.6.2
for inspection. Results logged to
/tmp/bundler20150921-23095-1bpxdrp/nokogiri-1.6.6.2/extensions/x86_64-linux/2.1.0/nokogiri-1.6.6.2/gem_make.out
An error occurred while installing nokogiri (1.6.6.2), and Bundler
cannot continue. Make sure that `gem install nokogiri -v '1.6.6.2'`
succeeds before bundling.

我尝试使用以下方式安装Nokogiri:

gem install nokogiri -v 1.6.6.2

但收到了这条消息:

ERROR:  While executing gem ... (Gem::FilePermissionError)
  You don't have write permissions for the /var/lib/gems/2.1.0 directory.

我也尝试过:

sudo gem install nokogiri -v 1.6.6.2

但收到了这条消息:

Building native extensions.  This could take a while... ERROR:  Error
installing nokogiri:    ERROR: Failed to build gem native extension.

    /usr/bin/ruby2.1 -r ./siteconf20150921-24140-1odizm6.rb extconf.rb checking if the C compiler accepts ... yes Building nokogiri using
packaged libraries. checking for gzdopen() in -lz... no zlib is
missing; necessary for building libxml2
*** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers.  Check
the mkmf.log file for more details.  You may need configuration
options.

Provided configuration options:     --with-opt-dir  --without-opt-dir
  --with-opt-include    --without-opt-include=${opt-dir}/include
  --with-opt-lib    --without-opt-lib=${opt-dir}/lib    --with-make-prog
  --without-make-prog   --srcdir=.  --curdir    --ruby=/usr/bin/ruby2.1
  --help    --clean     --use-system-libraries  --enable-static
  --disable-static  --with-zlib-dir     --without-zlib-dir
  --with-zlib-include   --without-zlib-include=${zlib-dir}/include
  --with-zlib-lib   --without-zlib-lib=${zlib-dir}/lib
  --enable-cross-build  --disable-cross-build

extconf failed, exit code 1

Gem files will remain installed in
/var/lib/gems/2.1.0/gems/nokogiri-1.6.6.2 for inspection. Results
logged to
/var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/nokogiri-1.6.6.2/gem_make.out

我是Ubuntu和Ruby on Rails的新手。我该如何解决这些问题?

1 个答案:

答案 0 :(得分:2)

看起来你缺少先决条件。

Nokogiri的“Troubleshooting Ubuntu/Debian Installation”文档说:

  

如果您发现自己处于这种情况,应该采取以下措施:

1 sudo apt-get install ruby-dev zlib1g-dev
     

如果这不适合您,请将其报告为错误(有关详细信息,请参阅“获取帮助”)。

因为您正在使用Ubuntu并进行正常安装,所以您需要sudo来执行任何gem安装。

我强烈建议使用rbenv或RVM来管理你的Ruby安装,因为它们会让你的生活变得更轻松。如果您使用这些,则除了任何系统范围的必备库之外,您不需要再次使用sudo