1.系统环境
2.安装CURL
在安装 Ruby 之前,先要安装 RVM:
$ curl -sSL https://get.rvm.io | bash -s stable
如果你已经安装了RVM,可以运行下面的命令,确保安装的是最新版本:
$ rvm get stable
运行下面的命令检查安装Ruby的需求条件:
$ rvm requirements
如果提示“command not found”,可以运行下面的命令:
$ 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.
检查是否安装成功:
root@ubuntu:~# rvm install 2.1.0
同前面一样需要等待一段时间,完成以后,Ruby,Ruby Gems就安装好了。
5.安装Rails
$ gem install rails --version 4.1.0 --no-ri --no-rdoc
检查Rails是否安装成功,执行以下命令显示Rails的版本号:
说明:如果出现ERROR: Could not find a valid gem 'rails' (= 4.1.0), here is why:
Unable to download data from https://rubygems.org/ - Errno::ECONNREFUSED: Connection refused - connect(2) for "s3.amazonaws.com" port 443 (https://api.rubygems.org/specs.4.8.gz)
解决方案: RubyGems 镜像
6.常用依赖
# apt-get install openssl libmysqlclient15-dev nodejs
7.经常遇到的问题
- 如果ubuntu自带的终端找不到ruby命令,可以按下面操作:
A RVM version 1.25.28 (stable) is installed yet 1.25.27 (stable) is loaded.
Please do one of the following:
* 'rvm reload'
* open a new shell
* 'echo rvm_auto_reload_flag=1 >> ~/.rvmrc' # for auto reload with msg.
* 'echo rvm_auto_reload_flag=2 >> ~/.rvmrc' # for silent auto reload.