Francis's Octopress Blog

A blogging framework for hackers.

Rvm常用用法

rvm常用用法

jhjguxin@jhjguxin-virtual-machine:~$ sudo gpasswd -a root rvm Adding user root to group rvm jhjguxin@jhjguxin-virtual-machine:~$ sudo gpasswd -a jhjguxin rvm Adding user jhjguxin to group rvm jhjguxin@jhjguxin-virtual-machine:~$ sudo gpasswd -a www-data rvm Adding user www-data to group rvm

这个是重点如果没有添加group的话则 install 会不成功 The installer no longer auto-adds root or users to the rvm group. Admins must do this. Also, please note that group memberships are ONLY evaluated at login time. This means that users must log out then back in before group membership takes effect!

  • If you have any questions, issues and/or ideas for improvement please fork the project and issue a pull request.

  • If you wish to disable the project .rvmrc file functionality, set rvm_project_rvmrc=0 in either /etc/rvmrc or ~/.rvmrc. then log out and back in.

  • You must read ‘rvm requirements’ for additional OS specific requirements for various rubies, and native-extension gems. Expect failures until those are met!

  • For screen users, please do not forget to read https://rvm.beginrescueend.com/workflow/screen/. You will need to add ‘shell –/bin/bash’ to your $HOME/.screenrc to properly load RVM.

  • rvm_trust_rvmrcs has been changed to rvm_trust_rvmrcs_flag for consistency

  • Project rvmrc files are now checked for trust whenever they change, as promised by the note displayed during the review process

  • Ruby package dependency list for your OS is given by: rvm requirements

  • If you encounter any issues with a ruby ‘X’ your best bet is to: rvm get head && rvm reinstall X

  • If you see the following error message: Unknown alias name: ‘default’ re-set your default ruby, this is due to a change in how default works.

  • after_use and after_cd hook now supports multiple files with after** the custom hooks can be easily turned on/off by: chmod +x $rvm_path/hooks/after_cd[hook_name] chmod -x $rvm_path/hooks/after_use[hook_name]

  • If your shell exits on entering directory with freshly checked out sources you should update .rvmrc file, and replace any exit with return.

  • If you wish to use RVM in an interactive fashion in other shells then place the following line at the end of your shell’s loading files (.bashrc or .bash_profile for bash and .zshenv for zsh), after all PATH/variable settings:

in my system

[-s “$HOME/.rvm/scripts/rvm”] source “$HOME/.rvm/scripts/rvm”  && echo “add rvm sucessful …” # This loads RVM into a shell session.

  • On some systems (like Ubuntu) rvmsudo requires following changes to work properly: http://stackoverflow.com/questions/257616/sudo-changes-path-why

  • To update RVM loading code append ‘—auto’ to ‘rvm get …’

  • In case you have some old RVM files/rubies in ‘/usr/local/bin’ or ‘$HOME/bin’ feel free to remove them, they were copied there because of bug in path detection.

  • ZSH 4.3.15 is buggy, be careful with it, it can break RVM, especially multiuser installations, You should consider downgrading ZSH to 4.3.12 which has proven to work more reliable with RVM.

RVM:  Shell scripts enabling management of multiple ruby environments.

RTFM: https://rvm.beginrescueend.com/

HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)

Screencast: http://screencasts.org/episodes/how-to-use-rvm

In case of any issues read output of ‘rvm requirements’ and/or ‘rvm notes’

Upgrade of RVM in /usr/share/ruby-rvm/ is complete.

jhjguxin,

#

   Thank you for using RVM!

   I sincerely hope that RVM helps to make your life easier and more enjoyable!!!

#

~Wayne

install Dependencies:(# libreadline6-dev is disable)

sudo apt-get install build-essential openssl libreadline6 curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion

If installation and configuration were successful, RVM should now load whenever you open a new shell. This can be tested by executing the following command which should output ‘rvm is a function’ as shown below.

user$ type rvm | head -1
rvm is a function

rvm常用用法 运行,

安装完成后,配置启动环境,修改~/.bashrc 文件,加入(我这里并不是这个文件但是只要找到就对)

add rvm

if [[ -s “$HOME/.rvm/scripts/rvm” ]]  ; then source “$HOME/.rvm/scripts/rvm” ; fi

在新的终端里就能看到rvm是否已安装成功:

$  rvm notes

RVM安装完成后,就可以通过TA来安装管理 Ruby 了。用下面一条命令来安装Ruby 1.9.2

$  rvm install 1.9.2

*Ruby包的下载实在太慢了,这里总是中断。有个小技巧,你可以用工具下载好ruby-1.9.2-p0.tar.bz2,然后手工放到~/.rvm/archives 目录下。然后再运行这条命令,就可以直接解压安装了。

 

把该版本的Ruby设为默认

rvm —help 获得rvm的常用用法:

rvm [Flags] [Options] Action [Implementation[,Implementation[,…]] rvm最常用的Action包括:

对Ruby的操作 主要包括读取,安装,卸载,更新,读取ruby等.

读取远程可安装的Ruby版本

获得当前可以用的ruby版本

rvm list known 安装Ruby

安装其中的ruby1.9.2-p290

rvm install ruby-1.9.2-p290 使用

切换到刚刚安装的ruby1.9.2-p290版本

rvm use ruby1.9.2-p290 读取

列出当前rvm下的ruby版本

rvm list

查询当前使用的ruby版本路径

which ruby

获得当前ruby版本

ruby -v 输出rvm当前使用的ruby版本与gemset信息: rvm info 在项目文件中使用RVM 在自己的项目根目录下面,创建一个.rvmrc文件,里面内容可以指定ruby版本与gemset。例如,某项目根目录下面的.rvmrc文件内容如下:

rvm ruby-1.9.2-p290@rails31 这表示,该项目使用ruby1.9.2p290这个版本的ruby,gem安装在rails31下面。然后iterm的zsh或者bash;或者TextMate中的rubymate,rakemate;以及pow等工具就可以直接调用相应ruby版本与相应gemset。

 

使用下面命令对RVM自己进行升级 $ rvm update

RVM 信息

通过以下几个命令查看当前RVM当前信息

$ rvm info $ rvm info 1.9.2 Ruby的安装使用与管理 用这个命令查看有哪些RVM可用的Ruby版本

$ rvm list known $ rvm install 1.9.2    # 安装 ruby-1.9.2 $ rvm install ree   # install Ruby Enterprise Edition (REE)

安装多个版本的Ruby之后,RVM可以很方便的进行切换。使用下条命令可以设置某一版本为当前使用版本。

$ rvm  ruby-1.8.7-p160 #切换1.8.7-p160为当前使用版本 $ rvm 1.8.7-p160    #同上面命令一样rvm ruby-1.8.7-p160 $ ruby -v #查看当前Ruby版本

 

查看当前Ruby的安装位置

$ which ruby 设置默认使用版本 将某一个版本的ruby设为默认,这样避免每次启动新的Shell都要选择所要使用的Ruby版本。

$ rvm —default use 1.8.7   #设置1.9.2为默认版本

$ rvm default      #通过default可以快速回到默认版本 $ rvm list default     #查看当前版本设置信息 $ rvm reset     #恢复系统默认设置 查看已安装的Ruby信息 列出所有已经安装的Ruby的版本信息

$ rvm list      #列出已安装的Ruby版本

$ rvm list rubies     #同上 $ rvm list default    #显示默认Ruby版本信息 $ rvm list known     #列出RVM所支持的所有Ruby版本的信息

创建别名 使用带版本号的ruby时,每次切换时都要输入很长的版本号,非常的不方便,通过使用别名功能,可以创建很简短的别名来代替长长的ruby信息。

$ rvm alias create reed ree-1.8.7-p2010.01    #为ree-187的Ruby版本创建一个别名叫:reed

$ rvm use reed  #通过别名迅速切换 $ rvm alias delete reed   #删除别名 $ rvm alias list # 查看所有的别名

删除已安装版本

$ rvm remove ruby-1.9.2-p0

$ rvm uninstall ruby-1.9.2-p0 管理 Gemsets 一个gemset就是一个目录,是某一个Ruby版本的Gem使用集,通过环境变量配置,使该gemset下的gem命令导入到Shell。

一个Ruby版本初装时就默认给了一个同名的gemset,也就是说rvm ruyb-1.9.2-p0 命令在执行时,就是使用该环境变量。

创建 基于指定Ruby版本创建一个新的Gemset

$ rvm 1.9.2  #??? $ rvm gemset create rails3  #创建一个名为rails3的gemset 使用 指定某一个gemset作为当前环境使用。

$ rvm 1.9.2  #???

$ rvm gemset use rails3   #在当前Ruby下使用rails3这个gemset

$ rvm use ruby-1.9.2-p0@rails3 #或者直接使用这种命名,直接指定ruby和gemset的信息。 $ rvm use ruby-1.9.2-p0@rails3 —default   #设置默认 查看Gemsets信息

$ rvm default  #选择使用ruby版本

列出当前Ruby版本下所有gemsets的信息r

$ rvm gemset list

列出所有Ruby版本下所有gemsets的信息

$ rvm gemset list_all 显示当前所使用的gemset信息 $ rvm gemset name     #当前gemset的名称

rails3 $ rvm gemdir   #所在位置 ~/.rvm/gems/ruby-1.9.2-p0@rails3 删除 删除一个gemset,默认有确认操作,使用 —force 可跳过该步骤。

$ rvm gemset delete rails3  #会让确认一次 $ rvm —force gemset delete rails3     #直接删除,没有确定步骤 清空 可以清空一个Gemset,删除其中的所有的gems包

$ rvm gemset empty rails3 $ rvm —force gemset empty rails3   #直接删除,没有确定步骤

导出 将当前gemsets内的信息导出到一个 name.gems文件,gems文件内定义gem的名称,版本号和其信赖关系。

$ rvm gemset export rails3.gems 导入 将gems文件所指定的gems安装到当前gemset下。

$ rvm gemset rails 3 $ rvm gemset import rails3 复制 可以将一个gemset内的所有gems包都复制到另一个gemset,很快速的复制一个当前环境。

$ rvm gemset copy 1.8.7@rails3 1.9.2-head@rails3

全局 gemsets (global gemsets)

每一个ruby版本都默认创建一个全局的gemset,以ruby_version@global命名,这样基于该ruby版本下所有的gemsets都会包含全局gemset里的gem包。可以起到统一约定的作用,也避免重复创建。 默认安装的global gemset内仅有一个gem包:rake

标签: rails ruby rvm