Linux 使用 apt-get install ruby​​ 2.0.0 安装 ruby​​ 成功但未使用正确的 ruby​​ 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18541695/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:43:08  来源:igfitidea点击:

installed ruby using apt-get install ruby 2.0.0 succeeded but not using correct ruby version

ruby-on-railsrubylinuxrvmlinux-mint

提问by Jngai1297

Hi I am really new to linux. I am currently deploying an app on digital ocean so I am switching to linux ox temporarily.

嗨,我对 linux 真的很陌生。我目前正在数字海洋上部署一个应用程序,所以我暂时切换到 linux ox。

I did

我做了

sudo apt-get install ruby 2.0.0 

and installed correctly but when I do ruby-v I am getting the 1.8.7 version.

并正确安装,但是当我执行 ruby​​-v 时,我得到了 1.8.7 版本。

I am sure that the old version is prepackaged with mint.

我确信旧版本是用薄荷预先包装的。

How do I switch to ruby 2.0.0 in my bash profile or the linux startup files?

如何在我的 bash 配置文件或 linux 启动文件中切换到 ruby​​ 2.0.0?

采纳答案by mbaird

If you're new to linux I'd recommend using something like RVM (Ruby Version Manager) to install ruby. It makes it easier to switch ruby versions and manage multiple gemsets.

如果您是 linux 新手,我建议您使用 RVM(Ruby 版本管理器)之类的工具来安装 ruby​​。它可以更轻松地切换 ruby​​ 版本和管理多个 gemset。

To install RVM with the latest (stable) ruby:

要使用最新的(稳定的)ruby 安装 RVM:

\curl -L https://get.rvm.io | bash -s stable --ruby

then check which rubies are installed by using

然后使用检查安装了哪些红宝石

rvm list

you can then switch ruby versions using

然后您可以使用切换 ruby​​ 版本

rvm use 2.0.0 --default

with the --defaultflag overriding any system ruby.

--default国旗覆盖的任何系统的红宝石。

Update
If you really don't want to use RVM, then use

更新
如果你真的不想使用 RVM,那么使用

sudo apt-get install checkinstall

wget -c http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz
tar -xzf ruby-2.0.0-p0.tar.gz
cd ruby-2.0.0-p0

./configure   
make

sudo checkinstall -y \
  --pkgversion 2.0.0-p0 \
  --provides "ruby-interpreter"

checkinstallwill package the source, making it easier to remove in the future

checkinstall会打包源码,方便以后删除

You'll then need to add the Ruby binaries to your path, by editing the env file:

然后,您需要通过编辑 env 文件将 Ruby 二进制文件添加到您的路径中:

sudo nano /etc/environment

add /usr/local/ruby/bin

添加 /usr/local/ruby/bin

PATH="/usr/local/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

then run

然后运行

source /etc/environment

to reload the file, and check your ruby version with

重新加载文件,并检查您的 ruby​​ 版本

ruby -v

回答by jamie

You didn't actually install ruby 2.x.x with that apt-getcommand. The normal repositories have ruby 1.8and ruby 1.9.1in them, currently.

您实际上并未使用该apt-get命令安装 ruby​​ 2.xx。正常的库具有ruby 1.8ruby 1.9.1在其中,目前。

There shouldn't be a space in your apt-getcommand either. With that command you would've installed ruby 1.9.1(which is the same thing as saying apt-get install ruby). The 2.0.0 would have been interpreted as a package name.

您的apt-get命令中也不应该有空格。使用该命令,您将安装ruby 1.9.1(这与说的相同apt-get install ruby)。2.0.0 将被解释为包名称。