如何在没有 RVM 的情况下在 Ubuntu 上安装 Ruby 2

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

How to install Ruby 2 on Ubuntu without RVM

rubyubuntu-12.04apt-getruby-2.0

提问by Mahmoud Khaled

I want to install ruby 2.0using

我想安装 ruby 2.0使用

sudo apt-get install ruby2.0

But there isn't available package for ruby2.0

但是没有适用于 ruby​​2.0 的包

I want to install it using apt-get installthe same like ruby 1.9.1

我想使用apt-get install安装它,就像 ruby​​ 1.9.1

Any suggestions?

有什么建议?

回答by danmanstx

sudo apt-get -y update
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p451.tar.gz
tar -xvzf ruby-2.0.0-p451.tar.gz
cd ruby-2.0.0-p451/
./configure --prefix=/usr/local
make
sudo make install

from here How do I install ruby 2.0.0 correctly on Ubuntu 12.04?

从这里如何在 Ubuntu 12.04 上正确安装 ruby​​ 2.0.0?

UPDATE

更新

for ruby 2.1.5

红宝石 2.1.5

sudo apt-get -y update
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget http://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz 
tar -xvzf ruby-2.1.5.tar.gz
cd ruby-2.1.5/
./configure --prefix=/usr/local
make
sudo make install

if you are still seeing an older ruby check your symlink ls -la /usr/bin/rubyfrom hector

如果您仍然看到较旧的 ruby​​,请检查您的ls -la /usr/bin/rubyhector符号链接

回答by Dokdo

sudo apt-add-repository ppa:brightbox/ruby-ng-experimental &&
sudo apt-get update &&
sudo apt-get install -y ruby2.0 ruby2.0-dev ruby2.0-doc

Easy to use ^?^

易于使用^?^

回答by Denis Denisov

# Adds Ruby 2.2 to Ubuntu 14.04
sudo apt-add-repository ppa:brightbox/ruby-ng
# Adds Ruby v1.9/2.0/2.1/2.2 to Ubuntu 14.04/15.04
# sudo add-apt-repository ppa:brightbox/ruby-ng-experimental

sudo apt-get update
sudo apt-get install ruby2.2 ruby2.2-dev

# http://stackoverflow.com/a/1892889/2126990
# priority ruby: https://gist.github.com/brodock/7693207
sudo update-alternatives --remove ruby /usr/bin/ruby2.2
sudo update-alternatives --remove irb /usr/bin/irb2.2
sudo update-alternatives --remove gem /usr/bin/gem2.2

sudo update-alternatives \
    --install /usr/bin/ruby ruby /usr/bin/ruby2.2 50 \
    --slave /usr/bin/irb irb /usr/bin/irb2.2 \
    --slave /usr/bin/rake rake /usr/bin/rake2.2 \
    --slave /usr/bin/gem gem /usr/bin/gem2.2 \
    --slave /usr/bin/rdoc rdoc /usr/bin/rdoc2.2 \
    --slave /usr/bin/testrb testrb /usr/bin/testrb2.2 \
    --slave /usr/bin/erb erb /usr/bin/erb2.2 \
    --slave /usr/bin/ri ri /usr/bin/ri2.2

update-alternatives --config ruby
update-alternatives --display ruby

$ irb
irb(main):001:0> RUBY_VERSION
=> "2.2.0"

$ ruby --version
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux-gnu]

回答by kikito

Since this question was answered I have found a new alternative here:

自从回答了这个问题后,我在这里找到了一个新的选择:

https://www.brightbox.com/docs/ruby/ubuntu/

https://www.brightbox.com/docs/ruby/ubuntu/

In short:

简而言之:

# For ubuntu >= 14.04 install software-properties-common
# instead of python-software-properties
sudo apt-get install python-software-properties
sudo apt-add-repository ppa:brightbox/ruby-ng
sudo apt-get update

sudo apt-get -y install ruby2.2 ruby-switch
sudo ruby-switch --set ruby2.2

I must say that according to my tests this is faster than the alternatives shown here, because the compiling step is skipped.

我必须说,根据我的测试,这比此处显示的替代方案更快,因为跳过了编译步骤。

回答by DMCoding

I particularly like ruby-install, available here: https://github.com/postmodern/ruby-install

我特别喜欢 ruby​​-install,可以在这里找到:https: //github.com/postmodern/ruby-install

It will install ruby (any version), JRuby, etc., and has many other features besides.

它将安装 ruby​​(任何版本)、JRuby 等,此外还有许多其他功能。

回答by Gautam Gahlawat

The better way to install ruby on ubuntu without RVM is to install it with rbenvin terminal as follows:

在没有 RVM 的情况下在 ubuntu 上安装 ruby​​ 的更好方法是在终端中使用rbenv安装它,如下所示:

$ sudo apt-get update

Install the rbenv and Ruby dependencies with apt-get:

使用 apt-get 安装 rbenv 和 Ruby 依赖项:

$ sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

Now run these commands as follows:

现在运行这些命令如下:

$ cd
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ exec $SHELL
$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
$ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
$ exec $SHELL

Time to install ruby:

安装 ruby​​ 的时间:

$ rbenv install 2.3.3

which ever is the latest and stable version

哪个是最新且稳定的版本

$ rbenv global 2.3.3

To check the version

检查版本

$ ruby -v

To disable the local documentation, as this process can be lengthy:

要禁用本地文档,因为此过程可能很长:

$ echo "gem: --no-document" > ~/.gemrc

Install the bundler gem, to manage your application dependencies:

安装 bundler gem,以管理您的应用程序依赖项:

$ gem install bundler