【问题标题】:How can I get permission to write to the gem directory in Ubuntu?如何获得写入 Ubuntu 中 gem 目录的权限?
【发布时间】:2015-09-21 16:56:37
【问题描述】:

我正在尝试在 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 的新手。我该如何解决这些问题?

【问题讨论】:

    标签: ruby-on-rails ruby linux ubuntu


    【解决方案1】:

    您似乎缺少先决条件。

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

    如果您发现自己处于这种情况,您应该这样做:

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

    如果这对您不起作用,请将其报告为错误(有关详细信息,请参阅获取帮助)。

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

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

    【讨论】:

      猜你喜欢
      • 2014-08-24
      • 1970-01-01
      • 1970-01-01
      • 2021-03-15
      • 1970-01-01
      • 2012-08-01
      • 2014-03-30
      • 2011-02-23
      相关资源
      最近更新 更多