简体   繁体   English

如何在Ubuntu 14.04上安装Ruby 2.1.4

[英]How to install Ruby 2.1.4 on Ubuntu 14.04

I dont know how to install the latest Ruby on Ubuntu. 我不知道如何在Ubuntu上安装最新的Ruby。

First I installed the default Ruby 1.9.3, using 首先,我使用了默认的Ruby 1.9.3

sudo apt-get install ruby

Then I tried to install the 2.0 version using 然后我尝试使用安装2.0版本

sudo apt-get install ruby2.0

My version of Ruby is still "ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux])" 我的Ruby版本仍然是“ruby 1.9.3p484(2013-11-22修订版43786)[x86_64-linux])”

What should I do? 我该怎么办?

There is a PPA with up-to-date versions of Ruby 2.x for Ubuntu 12.04+: 有一个针对Ubuntu 12.04+的最新版本的Ruby 2.x的PPA:

$ sudo apt-add-repository ppa:brightbox/ruby-ng
$ sudo apt-get update
$ sudo apt-get install ruby2.4

$ ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux-gnu]

First of all, install the prerequisite libraries: 首先,安装必备库:

sudo apt-get update
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

Then install rbenv, which is used to install Ruby: 然后安装rbenv,用于安装Ruby:

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

rbenv install 2.3.1
rbenv global 2.3.1
ruby -v

Then (optional) tell Rubygems to not install local documentation: 然后(可选)告诉Rubygems不安装本地文档:

echo "gem: --no-ri --no-rdoc" > ~/.gemrc

Credits: https://gorails.com/setup/ubuntu/14.10 致谢: https//gorails.com/setup/ubuntu/14.10

Warning!!! 警告!!! There are issues with Gnome-Shell . Gnome-Shell存在问题。 See comment below. 见下面的评论。

Best is to install it using rvm (ruby version manager). 最好是使用rvm (ruby版本管理器)安装它。
Run following commands in a terminal: 在终端中运行以下命令:

sudo apt-get update
sudo apt-get install build-essential make curl
\curl -L https://get.rvm.io | bash -s stable
source ~/.bash_profile
rvm install ruby-2.1.4

Then check ruby versions installed and in use: 然后检查安装和使用的ruby版本:

rvm list
rvm use --default ruby-2.1.4

Also you can directly add ruby bin path to PATH variable. 您也可以直接向PATH变量添加ruby bin路径。 Ruby is installed in Ruby安装在

$HOME/.rvm/rubies export PATH=$PATH:$HOME/.rvm/rubies/ruby-2.1.4/bin

Use RVM (Ruby Version Manager) to install and manage any versions of Ruby. 使用RVM (Ruby版本管理器)来安装和管理任何版本的Ruby。 You can have multiple versions of Ruby installed on the machine and you can easily select the one you want. 您可以在机器上安装多个版本的Ruby,您可以轻松选择所需的版本。

To install RVM type into terminal: 要将RVM类型安装到终端:

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

And let it work. 让它工作。 After that you will have RVM along with Ruby installed. 之后,您将安装RVM和Ruby。

Source: RVM Site 来源: RVM网站

update ubuntu: 更新ubuntu:

 sudo apt-get update
 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

Install rvm, which manages the ruby versions: 安装rvm,管理ruby版本:

to install rvm use the following command. 要安装rvm,请使用以下命令。

 \curl -sSL https://get.rvm.io | bash -s stable
 source ~/.bash_profile
 rvm install ruby-2.1.4

Check ruby versions installed and in use: 检查已安装和正在使用的ruby版本:

rvm list
rvm use --default ruby-2.1.4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM