天天看點

Linux安裝ruby

[url]https://rvm.io/[/url] 官方網站

[url]https://github.com/rvm/rvm[/url] 官方離線包

線上安裝步驟:

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

curl: (6) Couldn't resolve host 'get.rvm.io'

在浏覽器裡通路https://get.rvm.io會跳轉到下面的位址

https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer

修改安裝指令:

# \curl -sSL https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable

或者

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

或者

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

# source /usr/local/rvm/scripts/rvm

如果是在Centos上可以按下面操作:

* First you need to add all users that will be using rvm to 'rvm' group,

and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.

* To start using RVM you need to run `source /etc/profile.d/rvm.sh`

in all your open shell windows, in rare cases you need to reopen all shell windows.

# rvm -v

rvm 1.26.11 (latest) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]

# gem -v

2.4.8

# gem sources -l

*** CURRENT SOURCES ***

https://rubygems.org/

将gem的源更換為淘寶網,步驟如下:

# cd /usr/local/rvm/src/ruby-2.2.1/ext/zlib

# ruby ./extconf.rb

checking for deflateReset() in -lz... yes

checking for zlib.h... yes

checking for crc32_combine() in zlib.h... yes

checking for adler32_combine() in zlib.h... yes

checking for z_crc_t in zlib.h... no

creating Makefile

# make

linking shared-object zlib.so

# make install

/usr/bin/install -c -m 0755 zlib.so /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/x86_64-linux

# cd /usr/local/rvm/src/ruby-2.2.1/ext/openssl/

# ruby extconf.rb

checking for t_open() in -lnsl... no

checking for socket() in -lsocket... no

checking for assert.h... yes

checking for openssl/ssl.h... no

# make

# gem sources --remove https://rubygems.org/

https://rubygems.org/ removed from sources

# gem sources --add http://ruby.taobao.org/

或者

# gem sources -a https://ruby.taobao.org/

# gem sources -l

*** CURRENT SOURCES ***

http://ruby.taobao.org

----------------------------------------------------------------------------------

下面是離線安裝步驟:

在官方下載下傳rvm-master.zip離線安裝包并解壓:

# cd /opt

# mkdir ruby

# cd ruby

# ls

rvm-master.zip

# unzip rvm-master.zip -d /opt/ruby/

# ls

rvm-master rvm-master.zip

# cd rvm-master

# ./install

# source ~/.bashrc

# source ~/.bash_profile

# rvm list known

# rvm -v

rvm 1.26.11 (manual) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]

#

rvm安裝ruby:

在官方下載下傳ruby-2.1.8.tar.gz、ruby-2.1.8.tar.bz2和rubygems-2.5.1.tgz離線安裝包并拷貝到/usr/local/rvm/archives:

# pwd

/usr/local/rvm/archives

# ls

ruby-2.1.8.tar.bz2 ruby-2.1.8.tar.gz

# rpm -ivh libyaml-devel-0.1.3-1.el6.rf.x86_64.rpm --nodeps

# rpm -ivh readline-devel-6.0-4.el6.x86_64.rpm --nodeps

# rpm -ivh libffi-devel-3.0.5-3.2.el6.x86_64.rpm --nodeps

# rpm -ivh automake-1.11.1-4.el6.noarch.rpm --nodeps

# rpm -ivh libtool-2.2.6-15.5.el6.x86_64.rpm --nodeps

# rpm -ivh bison-2.4.1-5.el6.x86_64.rpm --nodeps

# rpm -ivh sqlite-devel-3.6.20-1.el6.x86_64.rpm --nodeps

# rvm install ruby-2.1.8

# rvm list

切換Ruby版本:

# rvm use 2.1.8

如果想設定為預設版本,這樣一來以後新打開的控制台預設的Ruby就是這個版本:

# rvm use 2.1.8 --default

解除安裝一個已安裝版本:

# rvm remove 2.1.8

安裝rubygems:

在官方下載下傳rubygems-2.5.1.tgz安裝包并解壓到/usr/local/rvm/src/目錄下:

# tar -zxvf rubygems-2.5.1.tgz -C /usr/local/rvm/src/

# cd /usr/local/rvm/src/rubygems-2.5.1

# rvm --create ruby-2.1.8

# rvm use ruby-2.1.8

Using /usr/local/rvm/gems/ruby-2.1.8

檢視gem安裝在哪裡:

# gem list –l

*** LOCAL GEMS ***

#

# vi .bash_profile

......

PATH=$PATH:$HOME/bin

# export PATH

export PATH="$HOME/.rbenv/bin:$PATH"

eval "$(rbenv init -)"

......

# ruby -v

ruby 2.1.8p440 (2015-12-16 revision 53160) [x86_64-linux]

# ls

appveyor.yml CVE-2013-4363.txt LICENSE.txt setup.rb

bin CVE-2015-3900.txt Manifest.txt test

CODE_OF_CONDUCT.md hide_lib_for_update MIT.txt UPGRADING.rdoc

CONTRIBUTING.rdoc History.txt Rakefile util

CVE-2013-4287.txt lib README.rdoc

# ruby setup.rb

......

RubyGems installed the following executables:

/usr/local/rvm/rubies/ruby-2.1.8/bin/gem

......

# /usr/local/rvm/rubies/ruby-2.1.8/bin/gem -v

2.5.1

繼續閱讀