Ruby-on-rails 使用 RVM 在 Ubuntu 上安装 Rails Path
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3518294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing Rails Path on Ubuntu with RVM
提问by user424703
I'm a linux noob running Ubuntu 10.04 and trying to install rails. I first installed ruby and then RVM and then downloaded and installed rubygems and then installed rails.
我是一个运行 Ubuntu 10.04 并尝试安装 rails 的 linux noob。我首先安装了ruby,然后安装了RVM,然后下载并安装了rubygems,然后安装了rails。
Rails only seems to respond if I have a 'sudo' in front of the command. If I write 'rails new test' in the terminal I get this:
如果我在命令前面有一个“sudo”,Rails 似乎只有响应。如果我在终端中写“rails new test”,我会得到这个:
/usr/local/lib/site_ruby/1.8/rubygems.rb:779:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
from /usr/local/lib/site_ruby/1.8/rubygems.rb:214:in `activate'
from /usr/local/lib/site_ruby/1.8/rubygems.rb:1082:in `gem'
from /usr/bin/rails:18
If I go to the terminal and write 'rails -v' I get the same thing:
如果我去终端并写“rails -v”,我会得到同样的结果:
/usr/local/lib/site_ruby/1.8/rubygems.rb:779:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
from /usr/local/lib/site_ruby/1.8/rubygems.rb:214:in `activate'
from /usr/local/lib/site_ruby/1.8/rubygems.rb:1082:in `gem'
from /usr/bin/rails:18
And if I go to the terminal and write 'sudo rails -v' I get the following: Rails 3.0.0.rc
如果我去终端并写“sudo rails -v”,我会得到以下信息:Rails 3.0.0.rc
'gem environment' gives me this:
“宝石环境”给了我这个:
RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2010-07-11 patchlevel -1) [i686-linux]
- INSTALLATION DIRECTORY: /home/josh/.rvm/gems/ruby-1.9.2-rc2@rails3tutorial
- RUBY EXECUTABLE: /home/josh/.rvm/rubies/ruby-1.9.2-rc2/bin/ruby
- EXECUTABLE DIRECTORY: /home/josh/.rvm/gems/ruby-1.9.2-rc2@rails3tutorial/bin
My suspicion is that my path is not set up correctly but I'm not sure how to fix it. Suggestions?
我怀疑我的路径设置不正确,但我不确定如何修复它。建议?
回答by scaganoff
I also experienced this problem on a clean install of Ubuntu 10.10...even after installing the rvm and ruby pre-requisites documented by "$ rvm notes".
我在全新安装 Ubuntu 10.10 时也遇到了这个问题……即使在安装了“$ rvm notes”记录的 rvm 和 ruby 先决条件之后。
It appears to be a problem with the "rvm" gem installation being unable to find the system zlib installation. Daniel's comment above is a great comment - a pity it is not listed as an answer.
似乎是“rvm”gem 安装无法找到系统 zlib 安装的问题。上面丹尼尔的评论是一个很好的评论 - 遗憾的是它没有被列为答案。
So the solution for me was to follow the instructions pointed out by Daniel at: https://rvm.beginrescueend.com/packages/zlib/.
所以我的解决方案是按照丹尼尔指出的说明进行操作:https: //rvm.beginrescueend.com/packages/zlib/。
$ rvm pkg install zlib
$ rvm remove 1.9.2
$ rvm install 1.9.2
The first command install zlib locally into your rvm area. The second command removes ruby 1.9.2 and the third command reinstalls ruby 1.9.2 with the rvm-local zlib.
第一个命令将 zlib 本地安装到您的 rvm 区域。第二个命令删除 ruby 1.9.2,第三个命令使用 rvm-local zlib 重新安装 ruby 1.9.2。
Thereafter set your ruby version and install gems:
此后设置您的 ruby 版本并安装 gems:
$ rvm use 1.9.2
$ gem install "whatever"
$ rvm 使用 1.9.2
$ gem install "whatever"
回答by Rob Di Marco
My guess is that you installed your gems using sudo (e.g. sudo gem install rails). When you use sudo to install, RVM is being ignored and the system ruby is being used.
我的猜测是您使用 sudo(例如sudo gem install rails)安装了 gem 。使用 sudo 安装时,会忽略 RVM 并使用系统 ruby。
When using RVM, you really don't want to install with sudo (note there is a command rvmsudo, to run your RVM setup through sudo, but you really rarely will use this). As you can see from your environment, your gems will be stored in /home/josh/.rvm/gems/ruby-1.9.2-rc2@rails3tutorial/gems, where you do not need root permissions to install.
使用 RVM 时,您真的不想使用 sudo 进行安装(请注意,有一个命令 rvmsudo,可以通过 sudo 运行您的 RVM 设置,但您很少会使用它)。从您的环境中可以看出,您的 gems 将存储在 /home/josh/.rvm/gems/ruby-1.9.2-rc2@rails3tutorial/gems 中,您不需要 root 权限即可安装。
So try:
所以尝试:
gem install rails
as yourself and see if everything is working.
就像你自己一样,看看一切是否正常。
回答by Ryan
If you are getting this warning, "ERROR: Loading command: update (LoadError) no such file to load -- zlib"
如果您收到此警告,“错误:正在加载命令:更新 (LoadError) 没有要加载的此类文件 -- zlib”
Basically, if the zlib library isn't there at the time you compile ruby, you just have to go back and install the library and then re-compile ruby.
基本上,如果编译 ruby 时 zlib 库不存在,则只需返回并安装该库,然后重新编译 ruby。
So try these steps
所以试试这些步骤
Uninstall ruby
rvm remove ruby-1.9.2
Install the necessary libraries
sudo apt-get install build-essential libssl-dev libreadline5 libreadline5-dev zlib1g zlib1g-dev
Reinstall ruby
rvm install 1.9.2
You will probably want to set this version of ruby as default
rvm use 1.9.2 --default
Just to be safe, close the terminal you currently have open and open a new one. You should be good to go from here.
卸载红宝石
rvm 删除 ruby-1.9.2
安装必要的库
sudo apt-get install build-essential libssl-dev libreadline5 libreadline5-dev zlib1g zlib1g-dev
重新安装红宝石
rvm 安装 1.9.2
您可能希望将此版本的 ruby 设置为默认值
rvm 使用 1.9.2 --default
为了安全起见,请关闭您当前打开的终端并打开一个新终端。你应该很高兴从这里走。
回答by Unitech
The solution is:
解决办法是:
apt-get install build-essential libssl-dev libreadline5 libreadline5-dev zlib1g zlib1g-dev
Then :
然后 :
rvm install ruby-1.9.2-p290
rvm default 1.9.2
回答by vich
As Rob Di Marco stated above, you cannot use sudo gem install railswith RVM (see the RVM Documentation).
正如 Rob Di Marco 上面所说,您不能sudo gem install rails与 RVM 一起使用(请参阅RVM 文档)。
I actually just asked a very similar question. I initially installed rails with sudo gem and when I attempted to install an older version of rails using RVM I ran into this issue. This was my code:
我实际上只是问了一个非常相似的问题。我最初使用 sudo gem 安装了 rails,当我尝试使用 RVM 安装旧版本的 rails 时,我遇到了这个问题。这是我的代码:
rvm use 1.8.7
rvm gemset create rails3.0.1
rvm [email protected]
sudo gem install rails --version=3.0.1 #the *sudo* in this line is WRONG
Another user (zetetic) suggested to uninstall your "sudo gem rails" with the following command:
另一个用户(zetetic)建议使用以下命令卸载“sudo gem rails”:
sudo gem uninstall rails
And then install again without sudo - gem install rails
然后在没有 sudo 的情况下再次安装 - gem install rails
After I did all of this I retried my original code and it worked, but this time without sudo:
在我完成所有这些之后,我重试了我的原始代码并且它起作用了,但是这次没有 sudo:
rvm use 1.8.7
rvm gemset create rails3.0.1
rvm [email protected]
gem install rails --version=3.0.1
The code above may only be relevant to you if you are attempting to use RVM, but to solve your problem, try uninstalling your sudo rails and re-installing without sudo. Worked for me. Good luck!
如果您尝试使用 RVM,上面的代码可能只与您相关,但要解决您的问题,请尝试卸载 sudo rails 并在没有 sudo 的情况下重新安装。对我来说有效。祝你好运!
回答by hahakubile
first, Install the necessary libs
sudo apt-get install build-essential libssl-dev libreadline5 libreadline5-dev zlib1g zlib1g-dev
then, Reinstall ruby 1.9.2
rvm reinstall 1.9.2 && rvm use 1.9.2
首先,安装必要的库
sudo apt-get install build-essential libssl-dev libreadline5 libreadline5-dev zlib1g zlib1g-dev
然后,重新安装 ruby 1.9.2
rvm 重新安装 1.9.2 && rvm 使用 1.9.2
回答by Kevin Sj?berg
No, all my gems are installed without sudo.
不,我所有的 gem 都是在没有sudo 的情况下安装的。
Here are some debug information that may help.
以下是一些可能有帮助的调试信息。
$PATH before rvm 1.9.2 --passenger
之前的 $PATH rvm 1.9.2 --passenger
/home/kevin/.rvm/gems/ruby-1.9.2-p0/bin: /home/kevin/.rvm/gems/ruby-1.9.2-p0@global/bin: /home/kevin/.rvm/rubies/ruby-1.9.2-p0/bin:/home/kevin/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/usr/games
/home/kevin/.rvm/gems/ruby-1.9.2-p0/bin: /home/kevin/.rvm/gems/ruby-1.9.2-p0@global/bin: /home/kevin/.rvm/ rubies/ruby-1.9.2-p0/bin:/home/kevin/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/用户/游戏
$PATH after rvm 1.9.2 --passenger
$PATH 之后 rvm 1.9.2 --passenger
/home/kevin/.rvm/gems/ruby-1.9.2-p0/bin: /bin:/home/kevin/.rvm/rubies/ruby-1.9.2-p0/bin:/home/kevin/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
/home/kevin/.rvm/gems/ruby-1.9.2-p0/bin: /bin:/home/kevin/.rvm/rubies/ruby-1.9.2-p0/bin:/home/kevin/.rvm /bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
This is my .bashrc file: http://pastebin.com/H9U3azAk
这是我的 .bashrc 文件:http: //pastebin.com/H9U3azAk
回答by Mayank Jain
if you are installing through source
如果您通过源代码安装
ext/Setup and uncomment the zlib line
$ ./configure
$ make
$ sudo make install
$ ruby -v
=> ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
$ gem -v
=> 1.3.7

