0.创建一个c9账户,https://c9.io
1.创建一个新的工作区,选择hosted workspace,选择一个空模板,创建,其他内容为空。
2.当工作区创建之后,在下面的shell下输入命令
curl -fsSL c9setup.saasbook.info
sudo bash --login
rvm use 2.4.0 --default
分别执行以上三条命令,这时候工作区创建完成。
3.创建一个公有的ssh密钥对,将这些密钥加入到github中。参考connecting to Github with ssh
打开git bash,可以输入
$ls -al ~/.ssh
检查当前有没有ssh密钥
键入
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
建议邮箱名与c9邮箱名相同,后续进行密码设置,可以自行操作。
将ssh密钥添加到ssh-agent中,
$ eval $(ssh-agent -s)
$ ssh-add ~/.ssh/id_rsa
将ssh密钥添加到github账户中,详情请见https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
可以用下面的一条命令检测你的ssh连接
$ ssh -T [email protected]
现在可以在c9上安装rails,
$ gem install rails -v 4.2.10
在c9上部署项目,用git clone 命令,然后切换到项目空间中,在c9的shell中运行
bundle install --without production
bundle exec rake db:setup
rails server -p $PORT -b $IP
运行以上三条命令之后,会在网页中看到运行成功的页面
第二部分:部署到heroku上
如果是windows,参考Getting Started on Heroku with Ruby (Microsoft Windows)
如果是Linux系统,参考Getting Started on Heroku with Ruby
这里,介绍windows的操作流程
首先下载jdk和jruby,我下载的jdk是11的,jruby是9.2.0下载安装成功后在本地机上运行下面命令,安装bundler,
jruby -S gem install bundler
安装heroku执行
heroku login
将项目克隆到本地,进入到该项目目录下,执行
heroku create
git push heroku master
heroku run rake db:setup
heroku run rake db:setup
至此,就完整的部署了。