rvm是一个命令行工具,可以提供一个便捷的多版本ruby环境的管理和切换。

https://rvm.io/

如果你打算学习ruby/rails, rvm是必不可少的工具之一。

这里所有的命令都是再用户权限下操作的,任何命令最好都不要用sudo.

rvm安装

$ curl -L get.rvm.io | bash -s stable
$ source ~/.bashrc
$ source ~/.bash_profile

修改 RVM 的 Ruby 安装源到国内的 淘宝镜像服务器,这样能提高安装速度

$ sed -i -e 's/ftp\.ruby-lang\.org\/pub\/ruby/ruby\.taobao\.org\/mirrors\/ruby/g' ~/.rvm/config/db

ruby的安装与切换

  • 列出已知的ruby版本
rvm list known
  • 安装一个ruby版本
rvm install 1.9.3

这里安装了最新的1.9.3, rvm list known列表里面的都可以拿来安装。

  • 使用一个ruby版本
rvm use 1.9.3

如果想设置为默认版本,可以这样

rvm use 1.9.3 --default 
  • 查询已经安装的ruby
rvm list
  • 卸载一个已安装版本
rvm remove 1.9.2

gemset的使用

rvm不仅可以提供一个多ruby版本共存的环境,还可以根据项目管理不同的gemset.

gemset可以理解为是一个独立的虚拟gem环境,每一个gemset都是相互独立的。

比如你有两个项目,一个是rails 2.3 一个是 rails 3. gemset可以帮你便捷的建立两套gem开发环境,并且方便的切换。

gemset是附加在ruby语言版本下面的,例如你用了1.9.2, 建立了一个叫rails3的gemset,当切换到1.8.7的时候,rails3这个gemset并不存在。

  • 建立gemset
rvm use 1.8.7
rvm gemset create rails23
  • 然后可以设定已建立的gemset做为当前环境

use 可以用来切换语言,或者gemset,前提是他们已经被安装(或者建立)。并可以在list命令中看到。

rvm use 1.8.7
rvm use 1.8.7@rails23

然后所有安装的gem都是安装在这个gemset之下。

  • 列出当前ruby的gemset
rvm gemset list
  • 清空gemset中的gem

如果你想清空一个gemset的所有gem,想重新安装所有gem,可以这样

rvm gemset empty 1.8.7@rails23
  • 删除一个gemset
rvm gemset delete rails2-3

项目自动加载gemset

rvm还可以自动加载gemset.

例如我们有一个rails3.1.3项目,需要1.9.3版本ruby.整个流程可以这样。

rvm install 1.9.3
rvm use 1.9.3
rvm gemset create rails313
rvm use 1.9.3@rails313

下面进入到项目目录,建立一个.rvmrc文件。

在这个文件里可以很简单的加一个命令:

rvm use 1.9.3@rails313

然后无论你当前ruby设置是什么,cd到这个项目的时候,rvm会帮你加载 ruby 1.9.3和rails313 gemset.

使用rvm来快速部署nginx+passenger

*首先安装passenger

gem install passenger

然后使用passenger-install-nginx-module 来安装nginx和部署。

因为这一步需要root权限(因为要编译nginx)可以用rvmsudo这个东西。(这个东西真是个好东西)

rvmsudo passenger-install-nginx-module

然后会让你选择是下载nginx源码自动编译安装,还是自己选择nginx源码位置。

选择nginx手动安装的可以添加别的编译参数,方便自定义编译nginx。

然后一路下载安装。默认的安装位置为/opt/nginx.

然后看看nginx.conf,都给你配置好了,只需要加上root位置(yourapp/public)就可以了。

当我第一次安装完成了,就惊呼,这也太爽了吧。

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

RubyGems 镜像 - 淘宝网

为什么有这个?

由于国内网络原因(你懂的),导致 rubygems.org 存放在 Amazon S3 上面的资源文件间歇性连接失败。所以你会与遇到 gem install rack 或 bundle install 的时候半天没有响应,具体可以用 gem install rails -V来查看执行过程。

这是一个完整 rubygems.org 镜像,你可以用此代替官方版本,同步频率目前为15分钟一次以保证尽量与官方服务同步。
如何使用?
$ gem sources --remove https://rubygems.org/
$ gem sources -a http://ruby.taobao.org/
$ gem sources -l
*** CURRENT SOURCES *** http://ruby.taobao.org
# 请确保只有 ruby.taobao.org
$ gem install rails
如果你是用 Bundle (Rails 项目)
source 'http://ruby.taobao.org/'
gem 'rails', '3.2.12'
...
Ruby 源代码下载
RVM 改用本站作为下载源, 提高 Ruby 安装速度
For Mac
$ sed -i .bak 's!ftp.ruby-lang.org/pub/ruby!ruby.taobao.org/mirrors/ruby!' $rvm_path/config/db
For Linux
$ sed -i 's!ftp.ruby-lang.org/pub/ruby!ruby.taobao.org/mirrors/ruby!' $rvm_path/config/db

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

https://github.com/saberma/vimfiles

介绍

这是经典的vim on rails开发工具

安装

请确保您已经安装了git-core,vim-7.2,ruby,rvm

sudo apt-get install exuberant-ctags ncurses-term vim-nox

git clone git://github.com/saberma/vimfiles.git ~/.vim

#初始化插件
cd ~/.vim
git submodule init
git submodule update
ln -s ~/.vim/vimrc ~/.vimrc cd ~/.vim/bundle/Command-T/ruby/command-t
#一定要先切换回ruby1.8.7,否则vim会报错:Vim: Caught deadly signal SEGV
rvm system
ruby extconf.rb
make
rvm default

注意

最新版本的rails vimfiles已经不再使用fuzzy_finder实现快速打开文件的功能,而改用CommandT
其快捷键也由原来的ctrl + t 改为 leader + t,leader键即\键

外部新增文件后,CommandT列表中看不到时,需要手动输入:CommandTFlush,刷新缓存

升级

2011.08.19已升级至最新版本,手动升级方法如下:

cd ~/.vim
git remote add akitaonrails git://github.com/akitaonrails/vimfiles.git
git pull akitaonrails master
git submodule foreach git pull

参考资源

使用说明参考这里

以下为akitaonrails原版详细说明:

Vim

It is recommended that you use gVim in either Windows or Linux and MacVim for
Mac. Download from:

Bundled Plugins

  • Ack – type :Ack [search pattern] to search your entire project
  • Align – align blocks of text using equal sign, make comment boxes and more
  • bufexplorer – manage your file buffers
  • Command-T – the fastest and most intuitive way for opening files in your project
  • cucumber – support for cucumber features such as syntax highlight, indentation, etc
  • endwise – support to close Ruby blocks such as ‘if’, ‘do’ with ‘end’
  • fugitive – support for Git, adding convenient commands such as :Gstatus, :Gread, :Gmove
  • haml – syntax highlight for HAML
  • html5.vim – omnicomplete function and syntax for HTML5
  • markdown – syntax highlight for Markdown
  • NERD_commenter – support to comment lines of code
  • NERD_tree – project pane that you can open with [leader] p
  • ragtag – easier way to create tags for html, erb, etc
  • rails – lot’s of tools to make it easier to manage your Rails projects
  • snipmate – support for textmate-like snippets for several languages
  • supertab – pseudo auto-complete with tab
  • surround – add, change, remove surrounding parentheses, brackets, quotes, etc
  • syntastic – checks for syntax errors in many languages
  • textile – syntax highlight for Textile
  • vim-coffee-script – syntax highlight for Coffee Script
  • vim-jade – Vim syntax highlighting for the Jade templating engine
  • vim-jquery – Vim syntax file to add some colorations for jQuery keywords and css selectors
  • vim-preview – [leader] P previews Markdown, Rdoc, Textile, html. Requires Ruby and other gems.
  • vim-ruby-sinatra – syntax highlight for Sinatra
  • vim-ruby – syntax highlight, smart identation, auto-complete for Ruby
  • vim-textobj-rubyblock – smart block selection in Ruby code
  • vividchalk – color scheme inspired by the classic Vibrant for Textmate
  • Zencoding – powerful way for HTML abbreviations (learn here: http://code.google.com/p/zen-coding/). Type abbreviation and press Ctrl+Y+comma (c-y ,)

Usage

Troubleshoot: Because of the large amount of submodules, if you ever have any
trouble after pulling from the repository, it will be easier to just back up
your old .vim folder and just git clone a new version.

Clone this repo into your home directory either as .vim (linux/mac) or
vimfiles (Windows). Such as:


git clone git://github.com/akitaonrails/vimfiles.git ~/.vim

Then ‘cd’ into the repo and run this to get the snippets submodule:


git submodule update --init

Now you should create a new .vimrc file in your home directory that
loads the pre-configured one that comes bundled in this package. You can do it
on Linux/Mac like this:


echo "source ~/.vim/vimrc" > ~/.vimrc

On Windows you should create a _vimrc (underline instead of dot) and add
the following line inside:


source ~/vimfiles/vimrc

This way you can override the default configuration by adding your own inside
this file.

You should also create a new .gvimrc file in your home directory. You can do
it on Linux/Mac like this:


echo "source ~/.vim/gvimrc" > ~/.gvimrc

On Windows you should create a _gvimrc (underline instead of dot) and add
the following line inside:


source ~/vimfiles/gvimrc

This way you can override the default GUI configuration by adding your own inside
this file.

Help Tags

At first usage of vim, type “:” while in command mode and execute:

call pathogen#helptags()

This will make the plugins documentations available upon :help

Dependencies

You will need these dependencies figured out:

In Ubuntu, for example, you will have to do:


apt-get install exuberant-ctags ncurses-term

In OS X, you can install ctags with homebrew


brew install ctags

On Windows you have to download Ctags and add ctags.exe in your PATH.

Mac OS X and most Linux distros come with Ruby already. If you’re in Windows
look for Luis Lavena’s latest Ruby Installer (http://rubyforge.org/projects/rubyinstaller/)

IMPORTANT: Command-T

The latest version replaces the old Fuzzy Finder with a new one called
“Command-T” form wincent.com. I’ve replaced the old “Command-T” key
binding that used to open new tabs and assigned it to this new plugin
so it behaves the same as Textmate.

You may have problems in Mac/Linux because this plugin requires a native
extension, so you will have to do this:


rvm use system # use this line if using rvm
cd ~/.vim/bundle/Command-T/ruby/command-t
ruby extconf.rb
make

This means that you need to have your Ruby source files and GCC also
installed. A binary for Windows is already bundled so it should just
work. I’ve also included a binary compiled for Ruby Enterprise Edition,
but if you are using other Ruby distros, you will need to recompile.

There are binaries for Mac and Windows. The Mac version is compiled
against the default system Ruby for Mac OS X 10.6.5. The Windows version
is compiled against Ruby Installer 1.8.7-p330.

Ubuntu 11.04 and/or Vim 7.3.35

Ubuntu 11.04 comes bundled with Vim 7.3.35, which has “flaky” Ruby support.
Even if you do everything right, you might see the following crashes when
trying to use Command-T:


Vim: Caught deadly signal SEGV
Vim: Finished. Segmentation fault

If this happens to you, update Vim to 7.3.154:


hg clone https://vim.googlecode.com/hg/ ~/vim
cd ~/vim
hg update -C v7-3-154
./configure --enable-rubyinterp
make
sudo make install

More details can be found here

Learn Vim

Visit the following sites to learn more about Vim:

There are many sites teaching Vim, if you know of any other that are easy
to follow for newcomers, let me know.

Credits

  • Original project and most of the heavy lifting: @scrooloose
  • All the cool plugins for Rails, Cucumber and more: @timpope
  • Great Command-T plugin by: Wincent
  • Hacks and some snippets: @akitaonrails

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

Installing Prebuilt Binaries with RVM

Originally posted 2012-12-21.

I've been working with a lot of virtual machines lately, and using RVM to install the version of ruby I need took longer than installing the base system. If you go through the motions of rvm install {VERSION}, you might just gloss over this message:

No binary rubies available for: ubuntu/12.04/x86_64/{VERSION}.

Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.

Not reading the documentation for rvm mount might end up costing you a lot of time.

RVM Prepare

RVM has a list of premade binaries that it will download if it gets the chance - you can see the list in/usr/local/rvm/config/remote or on github (I used a system-wide RVM install for this. Your path may be ~/.rvm/config/remote). For binaries that don't exist in that list, there's the option of packaging your own.

I'll be assuming that we're building a 2.0.0-preview2 binary, using a server you can scp files to, which is also accessable at http://artifacts.corp/binaries/

rvm install 2.0.0-preview2
rvm prepare 2.0.0-preview2 --install -r artifacts.corp:/var/www/binaries/

The rvm prepare command should have made a file called ruby-2.0.0-preview2.tar.bz2 in your current directory, and output something like the following.

--- upload:
ssh "artifacts.corp" "mkdir -p /var/www/binaries//ubuntu/12.04/x86_64/"
scp "ruby-2.0.0-preview2.tar.bz2" "artifacts.corp:/var/www/binaries//ubuntu/12.04/x86_64/ruby-2.0.0-preview2.tar.bz2"

RVM rightly cares quite a bit about the OS that the build will be installed on, and strongly recommends that you follow the naming convention seen in that output as a way to organize and name your builds. Once those commands are run and the file is uploaded, we'll be ready for the next time that we need to install 2.0.0-preview2 on this OS.

RVM Mount

There are two ways to download premade binaries - rvm install {name}, which uses the list of prebuilt binaries if possible, or rvm mount -r {URI}. The former works with data from configuration files, while the latter works using just command line parameters. Let's install our Ruby using mount first, since it takes fewer steps:

rvm mount -r http://artifacts.corp/binaries//ubuntu/12.04/x86_64/ruby-2.0.0-preview2.tar.bz2 --verify-downloads 1

On the VM I tested this with, rvm mount takes 12 seconds, while rvm install takes 4 minutes. Of course, there's that verify-downloads flag and the lists of prebuilt binaries left to explain..

RVM Remote

As mentioned above, RVM has a list of prebuilt binaries for different platforms that it can download. In addition to the file (on ubuntu) at /usr/local/rvm/config/remote, RVM will also use/usr/local/rvm/users/remote, if present. You can see the rubies that RVM can download as binaries for your system with rvm list remote

# Rubies available for 'ubuntu/12.04/x86_64':

    rbx-2.0.0-rc1
ruby-1.9.3-p194
ruby-1.9.3-p286
ruby-1.9.3-p327

If we add the URL to our precompiled 2.0.0-preview2 binary to /usr/local/rvm/users/remote, it will show up in that list.

root$ echo "http://artifacts.corp/binaries//ubuntu/12.04/x86_64/ruby-2.0.0-preview2.tar.bz2" >> /usr/local/rvm/user/remote
root$ rvm list remote # Rubies available for 'ubuntu/12.04/x86_64': rbx-2.0.0-rc1
ruby-1.9.3-p194
ruby-1.9.3-p286
ruby-1.9.3-p327
ruby-2.0.0-preview2

For this bit, there is every chance that I am missing, or misunderstanding, something. This may not be the best or right way to do things

Even though it shows up in the remote list, we still have to tell RVM that our server is an acceptable place to download rubies from. We do this by adding it to another textfile.

echo "rvm_remote_server_url=http://artifacts.corp/" >> /usr/local/rvm/user/db

Checksums

At this point, if you try rvm install 2.0.0-preview2 you would get an error message about checksums not matchng. With RVM's mount we used the --verify-downloads flag, which saves checksums of the file we download after the fact. Using that same flag, rvm install 2.0.0-preview2 --verify-downloads 1, will download and install the package correctly.

If however, you want to have RVM to use checksums to verify the download was successful, we can refer way back to the rest of the output from our rvm prepare command:

--- rvm/config/md5:
http://artifacts.corp/binaries/ruby-2.0.0-preview2.tar.bz2=fdb22cbad861616f5e3b56f0e3d976be
--- rvm/config/sha512:
http://artifacts.corp/binaries/ruby-2.0.0-preview2.tar.bz2=eb1972575cee09b0de59f39815b2f9992366cd6aaf3e32ab214d39b054029cf904260933e8b2fa101c7b5eb548d013e0e05c09d3e93dbc97a1ae55789d6a046b

And add those lines to our user/* files

echo "http://artifacts.corp/binaries/ubuntu/12.04/x86_64/ruby-2.0.0-preview2.tar.bz2=eb1972575cee09b0de59f39815b2f9992366cd6aaf3e32ab214d39b054029cf904260933e8b2fa101c7b5eb548d013e0e05c09d3e93dbc97a1ae55789d6a046b" >> /usr/local/rvm/user/sha512
echo "http://artifacts.corp/binaries/ubuntu/12.04/x86_64/ruby-2.0.0-preview2.tar.bz2=fdb22cbad861616f5e3b56f0e3d976be" >> /usr/local/rvm/user/md5

Now, rvm install 2.0.0-preview2 will download a prebuilt binary from a server of your choosing, as well as verify that the checksum is the same as the package you built at the very beginning.

Phew.

(转)rvm安装与常用命令的更多相关文章

  1. ios开发环境配置及cordova安装与常用命令

    一.ios开发环境配置 1.首先要有台Mac Book,如果有Mac Book,跳过步骤2.3.4,如果没有,执行步骤2.3.4: 2.下载并安装VMware Workstation,最好是下最新版本 ...

  2. Git安装以及常用命令(图文详解)

    **Git安装以及常用命令** 1.下载安装Git,傻瓜式安装相信大家都会. 官网下载地址:[https://git-scm.com/downloads] 2.Git基本操作 (1)git --ver ...

  3. linux基础学习之软件安装以及常用命令

    linux基础学习之软件安装以及常用命令 调用中央仓库: yum install wget 然后下载nodejs: wget https://nodejs.org/dist/v10.14.2/node ...

  4. Git安装和常用命令

    Git是目前世界上最先进的分布式版本控制系统!!! Git能自动帮我们记录每次文件的改动,还可以让同事协作编辑. 接下来,简单的介绍下Git的安装和常用命令: Git安装: 1.Windows系统,进 ...

  5. RabbitMQ入门教程(一):安装和常用命令

    原文:RabbitMQ入门教程(一):安装和常用命令 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn ...

  6. 记录redis安装及常用命令

    Redis安装及常用命令 一.安装 1.下载,解压,进入redis解压目录,make. make PREFIX=目录/redis install :安装到指定目录文件名为redis. 2.将解压目录里 ...

  7. 实验 1 Linux 系统的安装和常用命令

    实验 1 Linux 系统的安装和常用命令 (题目) 一.实验目的 (1)掌握 Linux 虚拟机的安装方法.Spark 和 Hadoop 等大数据软件在 Linux 操作系统 上运行可以发挥最佳性能 ...

  8. Redis笔记,安装和常用命令

    转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/96.html?1455870708 一.redis简单介绍 redis是N ...

  9. Redis总结笔记(一):安装和常用命令

    转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/112.html?1455860824 一.redis简单介绍 redis是 ...

随机推荐

  1. 075 Sort Colors 分类颜色

    给定一个包含红色.白色和蓝色,且含有 n 个元素的数组,对它们进行排序,使得相同颜色的元素相邻,颜色顺序为红色.白色.蓝色.此题中,我们使用整数 0, 1 和 2 分别表示红色,白色和蓝色.注意:不能 ...

  2. 《java学习三》jvm性能优化-------调优

    常见参数配置 -XX:+PrintGC      每次触发GC的时候打印相关日志 -XX:+UseSerialGC      串行回收 -XX:+PrintGCDetails  更详细的GC日志 -X ...

  3. java中两个map比较

    一 /** * 用map的keySet()的迭代器(性能效率较低) * */ public void compareMap1 (){ Map<String, String> m1 = ne ...

  4. fleet-运行一个全局的单元

    运行一个全局的单元 正如前面所提到的,全局单元是有用的,用于在您的集群中的所有机器上运行一个单元.它不会比一个普通的单元差太多,而是一个新的x-fleet参数称为Global=true.这是一个示例单 ...

  5. <Android 应用 之路> 天气预报(三)

    昨天介绍了基本的载入界面,今天介绍下天气信息显示界面的代码 基本ListView显示 搜索框,查询城市 上一篇文章中,载入界面通过showWeatherInfo()方法跳转到天气信息显示界面 priv ...

  6. SpringMVC+Thymeleaf 简单使用

    一.简介 1.Thymeleaf 在有网络和无网络的环境下皆可运行,而且完全不需启动WEB应用,即它可以让美工在浏览器查看页面的静态效果,也可以让程序员在服务器查看带数据的动态页面效果.浏览器解释 h ...

  7. javascript简单计算器实践

    参考部分资料,编写一个简单的计算器案例,虽然完成了正常需求,但是也有不满之处,待后续实力提升后再来补充,先把不足之处列出: 1:本来打算只要打开页面,计算器的输入框会显示一个默认为0的状态,但是在输入 ...

  8. 转载《五大免费采集器哪个好,火车头,海纳,ET,三人行,狂人采集 》

    在目前的站长圈内,比较流行的采集工具有很多,但是总结起来,比较出名的免费的就这么几个:火车头,海纳,ET,三人行,狂人. 下面我们对这几款采集工具作一个简单的评比. 1.火车头 基本上人人都知道,那就 ...

  9. javaSe数据类型

    在学完了java程序的结构以及注释后呢按照一般的教程我们应该学点什么呢?   没错就是变量和数据类型[其实我的内心是拒绝的,又是无聊的一大堆,不仅无聊,还得掌握] 好了首先介绍什么是变量: 变量:变量 ...

  10. DDOS介绍

    DDOS: Data Domain Operating System(DD OS),即数据域操作系统----管理EMC的数据域拷贝存储系统(powers EMC Data Domain dedupli ...