1、登录到云服务器(ssh ubuntu@45.40.245.66),
//其中ubuntu是实例名,45.40.245.66是主ip地址里面的公网ip,登录时需要换成你自己的公网ip xuzhaoning@xuchaoningdeAir:~$ ssh ubuntu@45.40.245.66 //系统返回信息 ubuntu@45.40.245.66's password: //第一次输入密码输入错误会出现这个提示 Permission denied, please try again. //第二次密码输入正确 ubuntu@45.40.245.66's password: //已经登录成功了 Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-91-generic x86_64) * Documentation: [https://help.ubuntu.com](https://help.ubuntu.com) * Management: [https://landscape.canonical.com](https://landscape.canonical.com) * Support: [https://ubuntu.com/advantage](https://ubuntu.com/advantage) Last login: Sun Feb 17 14:11:26 2019 from 111.201.231.215 ubuntu@VM-16-15-ubuntu:~$
2、更新源列表
ubuntu@VM-16-15-ubuntu:~$ sudo apt-get update
3、安装依赖插件
ubuntu@VM-16-15-ubuntu:~$ sudo apt-get install -y git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common
4、安装rbenv(rbenv是一个安装 ruby 和管理控制多个 ruby 版本的工具)
ubuntu@VM-16-15-ubuntu:~$ git clone git://github.com/sstephenson/rbenv.git .rbenv ubuntu@VM-16-15-ubuntu:~$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc ubuntu@VM-16-15-ubuntu:~$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc ubuntu@VM-16-15-ubuntu:~$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build ubuntu@VM-16-15-ubuntu:~$ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc ubuntu@VM-16-15-ubuntu:~$ exec $SHELL
5、用rbenv安装ruby2.3.5版本。最好找个网速快的地方,大概需要十分钟左右
ubuntu@VM-16-15-ubuntu:~$ rbenv install 2.3.5 #系统返回信息 -> Installing ruby-2.3.5... Installed ruby-2.3.5 to /root/.rbenv/versions/2.3.5
运行完再运行这一句
ubuntu@VM-16-15-ubuntu:~$ rbenv global 2.3.5
6、将gem源换成国内源(gem就是咱们做项目需要用到的插件,比如我们需要做一个分页的功能,不需要自己写具体分页的代码,只需要安装上一个名为kaminari的gem,分页功能就可以直接使用了,换成国内源会使下载gem的速度更快)
(1)查看现在的gem源
ubuntu@VM-16-15-ubuntu:~$ gem sources -l #系统返回信息 *** CURRENT SOURCES *** https://rubygems.org/
(2)修改gem源
ubuntu@VM-16-15-ubuntu:~$ gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/ #系统返回信息 https://gems.ruby-china.com/ added to sources https://rubygems.org/ removed from sources
(3)查看修改后的gem源
ubuntu@VM-16-15-ubuntu:~$ gem sources -l #系统返回信息 *** CURRENT SOURCES *** https://gems.ruby-china.com/
7、安装rails 4.2.1版本
(1)安装rails4.2.1版本
ubuntu@VM-16-15-ubuntu:~$ gem install rails -v 4.2.1
(2)告知rbenv安装了新的rails版本
ubuntu@VM-16-15-ubuntu:~$ rbenv rehash
(3)查看当前rails版本
ubuntu@VM-16-15-ubuntu:~$ rails -v
8、安装mysql数据库以及依赖插件,安装过程需要设置mysql密码,该密码一定要记住,之后登录数据库会用到
ubuntu@VM-16-15-ubuntu:~$ sudo apt-get install mysql-server mysql-client libmysqlclient-dev