您的位置:首页 > 编程语言 > Ruby

记录从零开始在Ubuntu 16.04 上部署Ruby on rails 项目

2017-03-07 11:43 531 查看
之前学习Java Web项目时,在亚马逊云(aws)上部署了一台 Windows Server,最近在学习Ruby,跟着官网把小博客写完了,感觉挺好玩的,也想部署到这个上面,怎奈都说不建议或者直接让放弃Windows,然后我又弄了一台Ubuntu的服务器,从零开始,也记录在这遇到的一些坑.

1.先安装RVM,这个apt-get 并没有提供,所以使用官网的安装方式安装

\curl -sSL https://get.rvm.io | bash -s stable
也可以使用gpg,不过我在本地弄Ubuntu时也是用的这个,所以就一直用这个了,这里不得不说,因为服务器放在东京区了,所有下载什么的都很快,不用考虑墙的问题.
安装完成后运行rvm 是不识别的 要先 source .profile

其实因为一直在用 OS X,好像是比较喜欢 .bash_profile,但是既然转到服务器不是多用户,就用.profile吧

2.使用RVM安装Ruby

如果使用最新版本 rvm install ruby 就可以了,也可以指定版本 如 rvm install ruby-2.3.1

gem就随Ruby一起安装好了

3.使用GEM安装rails

gem install rails

4.先创建一个示例程序www

rails new www,运行完之后是不能启动的 因为我们需要JavaScript运行时环境,好解决这个问题

5.安装 NVM

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash同样的安装完成后需要 source .profile

6.使用NVM安装Node.js

nvm install node

至此,我们再进入到www目录内 启动服务,如下图所示

ubuntu@ip-172-31-5-144:~/workspace/ruby/project/www$ rails s
=> Booting Puma
=> Rails 5.0.2 application starting in development on http://localhost:3000 => Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.7.1 (ruby 2.4.0-p0), codename: Snowy Sagebrush
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: