How to install Ruby 2 on Ubuntu without RVM

2019-01-16 01:37发布

I want to install ruby 2.0 using

sudo apt-get install ruby2.0

But there isn't available package for ruby2.0

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

Any suggestions?

6条回答
该账号已被封号
2楼-- · 2019-01-16 02:18
# 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]
查看更多
混吃等死
3楼-- · 2019-01-16 02:24

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

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.

查看更多
劳资没心,怎么记你
4楼-- · 2019-01-16 02:25

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

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

查看更多
Deceive 欺骗
5楼-- · 2019-01-16 02:32
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?

UPDATE

for ruby 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/ruby from hector

查看更多
再贱就再见
6楼-- · 2019-01-16 02:33

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

$ sudo apt-get update

Install the rbenv and Ruby dependencies with apt-get:

$ 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:

$ 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:

$ gem install bundler
查看更多
姐就是有狂的资本
7楼-- · 2019-01-16 02:34
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 ^ㅡ^

查看更多
登录 后发表回答