在安装ruby gems时构建本机扩展错误

时间:2021-07-15 07:16:36

I installed a ruby version as below

我安装了一个ruby版本,如下所示

$ rvm install ruby-1.9.3-p448-dev

and when i checked version as below

当我检查版本如下

$ ruby -v

ruby 1.9.3p448 (2013-06-27 revision 41675) [i686-linux]

But when i tried to install travis like below

但是当我试着像下面这样安装travis时

$ gem install travis

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

    /home/user/.rvm/rubies/ruby-1.9.3-p448/bin/ruby extconf.rb
/home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1371:in `initialize': Permission denied - /home/user/.travis/travis.sh (Errno::EACCES)
    from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1371:in `open'
    from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1371:in `block in copy_file'
    from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1370:in `open'
    from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1370:in `copy_file'
    from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:477:in `copy_file'
    from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:396:in `block in cp'
    from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1515:in `block in fu_each_src_dest'
    from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1529:in `fu_each_src_dest0'
    from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1513:in `fu_each_src_dest'
    from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:395:in `cp'
    from extconf.rb:5:in `<main>'


Gem files will remain installed in /home/user/.rvm/gems/ruby-1.9.3-p448/gems/travis-1.5.2 for inspection.
Results logged to /home/user/.rvm/gems/ruby-1.9.3-p448/gems/travis-1.5.2/completion/gem_make.out

So how to avoid the above native extensions error and install the travis succesfully using gem

因此,如何避免上述本机扩展错误并成功地使用gem安装travis

Edit

编辑

When i tried the command by including sudo as below

当我尝试包括sudo的命令时。

sudo gem install travis

I am getting the below message as success

我得到的信息是成功

Building native extensions.  This could take a while...
Successfully installed travis-1.5.2
1 gem installed
Installing ri documentation for travis-1.5.2...
Installing RDoc documentation for travis-1.5.2...

And now what all i am trying to do is to set up environ variables on travis and hence i tried the following command

现在我要做的就是在travis上设置环境变量,因此我尝试了下面的命令

$ travis encrypt -r travis_uname/app_name EMAIL_HOST_KEY=key_value

and getting the below wierd error

得到下面的误差

/usr/lib/ruby/vendor_ruby/1.8/rubygems/dependency.rb:247:in `to_specs': Could not find travis (>= 0) amongst [addressable-2.3.5, backports-3.3.3, bundler-1.3.5, bundler-unload-1.0.1, coderay-1.0.9, ethon-0.6.0, faraday-0.8.8, faraday_middleware-0.9.0, ffi-1.9.0, gh-0.11.3, highline-1.6.19, launchy-2.3.0, method_source-0.8.2, mime-types-1.24, multi_json-1.7.9, multipart-post-1.2.0, net-http-persistent-2.9, net-http-pipeline-1.0.1, netrc-0.7.7, pry-0.9.12.2, pusher-client-0.3.1, rake-10.1.0, ruby-hmac-0.4.0, rubygems-bundler-1.2.2, rubygems-update-2.0.7, rvm-1.11.3.8, slop-3.4.6, typhoeus-0.6.4, websocket-1.0.7, websocket-native-1.0.0] (Gem::LoadError)
    from /usr/lib/ruby/vendor_ruby/1.8/rubygems/dependency.rb:256:in `to_spec'
    from /usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:1208:in `gem'
    from /usr/local/bin/travis:18

So finally how to avoid above error and make the above travis command work successfully ?

最后,如何避免上述错误,使上述特拉维斯命令顺利工作?

3 个解决方案

#1


4  

First of all, set the Ruby version you are using as a default

首先,将使用的Ruby版本设置为默认版本

rvm use --default ruby-1.9.3-p448-dev

and uninstall the gem previously installed with sudo

卸载之前安装在sudo上的gem。

sudo gem uninstall travis

this makes sure that all your commands are using the same Ruby version and your machine is clean again. Now to your installation problem. This error

这确保您的所有命令都使用相同的Ruby版本,并且您的机器再次保持干净。现在来看看你的安装问题。这个错误

Permission denied - /home/user/.travis/travis.sh (Errno::EACCES)

shows you, that the installer tried to access /home/user/.travis but wasn't able to do so due to a lack of user permissions. This means you need to make sure that the folder belongs to you and is writeable

显示安装程序试图访问/home/user/。但是由于缺乏用户权限,特拉维斯不能这么做。这意味着您需要确保该文件夹属于您,并且是可写的

chown -R `whoami` ~/.travis
chmod -R u+wx ~/.travis

Now go ahead and try to re-install:

现在继续尝试重新安装:

gem install travis

and everything should be fine.

一切都会好起来的。

#2


2  

Installing the -dev packages fixed it for me... sudo apt-get install ruby-dev

安装-dev包为我修复了它……sudo apt-get安装ruby-dev

#3


0  

It happens sometimes when you install some gems with sudo and other not. Ideally you should never sudo for the gem install. So if you have several gems owned by root and you want to remove the ruby installation and the related gems, run this command:

当你用sudo安装一些gem而不是其他的时候就会发生这种情况。理想情况下,您不应该为gem安装提供sudo。因此,如果您有几个gem归root所有,并且想要删除ruby安装和相关的gems,请运行以下命令:

sudo rvm remove ruby-2.0.0-p353 --gems

sudo rvm删除ruby-2.0 -p353——gems

rvm remove is the preferred way of removing rubies from rvm. By default, not only will it remove the ruby and it's source files, it will also get rid of aliases, wrappers, environments and any associated binaries - in other words, it cleans up most of the install.

rvm删除是rvm中去除红宝石的首选方法。默认情况下,它不仅将删除ruby及其源文件,还将删除别名、包装器、环境和任何相关的二进制文件——换句话说,它将清理大部分安装。

The --gems flag will get rid of all associated gemsets.

——gems标记将删除所有相关的gemset。

The you should reinstall your ruby version with: rvm install ruby-2.0.0-p353 and bundle install again.

您应该使用:rvm安装ruby-2.0 -p353重新安装您的ruby版本,并重新打包安装。

#1


4  

First of all, set the Ruby version you are using as a default

首先,将使用的Ruby版本设置为默认版本

rvm use --default ruby-1.9.3-p448-dev

and uninstall the gem previously installed with sudo

卸载之前安装在sudo上的gem。

sudo gem uninstall travis

this makes sure that all your commands are using the same Ruby version and your machine is clean again. Now to your installation problem. This error

这确保您的所有命令都使用相同的Ruby版本,并且您的机器再次保持干净。现在来看看你的安装问题。这个错误

Permission denied - /home/user/.travis/travis.sh (Errno::EACCES)

shows you, that the installer tried to access /home/user/.travis but wasn't able to do so due to a lack of user permissions. This means you need to make sure that the folder belongs to you and is writeable

显示安装程序试图访问/home/user/。但是由于缺乏用户权限,特拉维斯不能这么做。这意味着您需要确保该文件夹属于您,并且是可写的

chown -R `whoami` ~/.travis
chmod -R u+wx ~/.travis

Now go ahead and try to re-install:

现在继续尝试重新安装:

gem install travis

and everything should be fine.

一切都会好起来的。

#2


2  

Installing the -dev packages fixed it for me... sudo apt-get install ruby-dev

安装-dev包为我修复了它……sudo apt-get安装ruby-dev

#3


0  

It happens sometimes when you install some gems with sudo and other not. Ideally you should never sudo for the gem install. So if you have several gems owned by root and you want to remove the ruby installation and the related gems, run this command:

当你用sudo安装一些gem而不是其他的时候就会发生这种情况。理想情况下,您不应该为gem安装提供sudo。因此,如果您有几个gem归root所有,并且想要删除ruby安装和相关的gems,请运行以下命令:

sudo rvm remove ruby-2.0.0-p353 --gems

sudo rvm删除ruby-2.0 -p353——gems

rvm remove is the preferred way of removing rubies from rvm. By default, not only will it remove the ruby and it's source files, it will also get rid of aliases, wrappers, environments and any associated binaries - in other words, it cleans up most of the install.

rvm删除是rvm中去除红宝石的首选方法。默认情况下,它不仅将删除ruby及其源文件,还将删除别名、包装器、环境和任何相关的二进制文件——换句话说,它将清理大部分安装。

The --gems flag will get rid of all associated gemsets.

——gems标记将删除所有相关的gemset。

The you should reinstall your ruby version with: rvm install ruby-2.0.0-p353 and bundle install again.

您应该使用:rvm安装ruby-2.0 -p353重新安装您的ruby版本,并重新打包安装。