Ruby on Railsruby小白课程实战--宠物论坛

【Ruby on Rails全栈课程】5.2 项目上线--在云服

2019-02-20  本文已影响2人  808cb3be8e58
1、打开Ubuntu系统(Windows系统打开虚拟机登录到Ubuntu系统;IOS系统在终端打开rails-va文件夹cd rails-va,输入vagrant up,再输入vagrant ssh),更新源列表

vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get update

2、安装依赖插件

vagrant@vagrant-ubuntu-trusty-64:~$ 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

3、安装rbenv(rbenv是一个安装 ruby 和管理控制多个 ruby 版本的工具)

vagrant@vagrant-ubuntu-trusty-64:~$ git clone [git://github.com/sstephenson/rbenv.git](git://github.com/sstephenson/rbenv.git) .rbenv

vagrant@vagrant-ubuntu-trusty-64:~$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc

vagrant@vagrant-ubuntu-trusty-64:~$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc

vagrant@vagrant-ubuntu-trusty-64:~$ git clone [git://github.com/sstephenson/ruby-build.git](git://github.com/sstephenson/ruby-build.git) ~/.rbenv/plugins/ruby-build

vagrant@vagrant-ubuntu-trusty-64:~$ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc

vagrant@vagrant-ubuntu-trusty-64:~$ exec $SHELL

4、用rbenv安装ruby2.3.5版本。最好找个网速快的地方,大概需要十分钟左右

vagrant@vagrant-ubuntu-trusty-64:~$ rbenv install 2.3.5

#系统返回信息

Downloading ruby-[2.3.5.tar.bz2](2.3.5.tar.bz2)...

-> [[https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.5.tar.bz2](https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.5.tar.bz2)]([https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.5.tar.bz2](https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.5.tar.bz2))

Installing ruby-2.3.5...

Installed ruby-2.3.5 to /home/vagrant/.rbenv/versions/2.3.5

运行完再运行这一句


vagrant@vagrant-ubuntu-trusty-64:~$ rbenv global 2.3.5

5、将gem源换成国内源(gem就是咱们做项目需要用到的插件,比如我们需要做一个分页的功能,不需要自己写具体分页的代码,只需要安装上一个名为kaminari的gem,分页功能就可以直接使用了,换成国内源会使下载gem的速度更快)

(1)查看现在的gem源


vagrant@vagrant-ubuntu-trusty-64:~$ gem sources -l

#系统返回信息

*** CURRENT SOURCES ***

[https://rubygems.org/](https://rubygems.org/)

(2)修改gem源


vagrant@vagrant-ubuntu-trusty-64:~$ gem sources --add  [https://gems.ruby-china.com/](https://gems.ruby-china.com/) --remove [https://rubygems.org/](https://rubygems.org/)

#系统返回信息

[https://gems.ruby-china.com/](https://gems.ruby-china.com/) added to sources

[https://rubygems.org/](https://rubygems.org/) removed from sources

(3)查看修改后的gem源


vagrant@vagrant-ubuntu-trusty-64:~$ gem sources -l

#系统返回信息

*** CURRENT SOURCES ***

[https://gems.ruby-china.com/](https://gems.ruby-china.com/)

6、安装rails 4.2.1版本

(1)安装rails4.2.1版本


vagrant@vagrant-ubuntu-trusty-64:~$ gem install rails -v 4.2.1

(2)告知rbenv安装了新的rails版本


vagrant@vagrant-ubuntu-trusty-64:~$ rbenv rehash

(3)查看当前rails版本


vagrant@vagrant-ubuntu-trusty-64:~$ rails -v

7、安装mysql数据库以及依赖插件,安装过程需要设置mysql密码,该密码一定要记住,之后登录数据库会用到

vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get install mysql-server mysql-client libmysqlclient-dev

上一篇下一篇

猜你喜欢

热点阅读