手把手學ROR一——Ruby on Rails在Linux上的環境搭建

第一次接觸Ruby on Rails, mark一下

1.準備環境。

我是直接在cloud上劃拉了一塊地方,用的Ubuntu的系統。

root@haiyu-personal:~# uname -a
Linux haiyu-personal 4.15.0-58-generic #64-Ubuntu SMP Tue Aug 6 11:12:41 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

2.安裝ruby

2.1 設置代理。

我的機器需要設置代理,在文件下  ~/.bashrc  添加:

export http_proxy=http://10.XXX.X.XX:8080
export https_proxy=http://10.XXX.X.XX:8080

記得source 一下生效

2.2 安裝RVM

執行這個即可,但是我這邊設置代理後還是提示網絡不好,鏈接不上“gpg: keyserver receive failed: Connection timed out”

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash

網上查了一下可以這樣設置https://askubuntu.com/questions/53146/how-do-i-get-add-apt-repository-to-work-through-a-proxy/102505#102505

直接把代理指定好,執行沒問題

gpg --keyserver-options http-proxy=http://10.xxx.x.xx:8080 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

執行好兩條命令後RVM 就安裝好了,可以看到我的版本啦

root@haiyu-personal:~# rvm -v
rvm 1.29.10-next (master) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

不行的可以source一下讓修改生效,可以試試這個命令

source /usr/local/rvm/scripts/rvm

實在不知道怎麼source的就退出再進來

2.3 安裝Ruby

rvm install 2.5.5

寫你想要的版本,安裝好啦

root@haiyu-personal:~# ruby -v
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]

3 安裝rails

gem install rails -v 5.2.1

好啦,都安裝好啦。

 

可以新建項目了,使用命令“rails new your_project_name -d mysql”建好你的項目

————————————————————分割線——————————————————————

基本到這就可以結束了,後面是我自己的項目需要一些包需要手動安裝,有問題不怕,Google。

對於已經存在的項目,點進去,先執行“bundle install”可以自動安裝依賴項

Q1:"An error occurred while installing capybara-webkit (1.15.0), and Bundler cannot continue.
Make sure that `gem install capybara-webkit -v '1.15.0' --source 'http://gem.wft.int.net.nokia.com/'` succeeds before bundling."
S1: https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit#debian--ubuntu

sudo apt-get update
sudo apt-get install g++ qt5-default libqt5webkit5-dev gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-x

Q2:"An error occurred while installing charlock_holmes (0.7.6), and Bundler cannot continue.
Make sure that `gem install charlock_holmes -v '0.7.6' --source 'http://gem.wft.int.net.nokia.com/'` succeeds before bundling."

S2:https://askubuntu.com/questions/243645/how-can-i-install-development-libraries-for-icu-le-and-icu-uc

sudo apt-get install libicu-dev

Q3:"An error occurred while installing libxml-ruby (3.1.0), and Bundler cannot continue.
Make sure that `gem install libxml-ruby -v '3.1.0' --source 'http://gem.wft.int.net.nokia.com/'` succeeds before bundling."

S3:https://askubuntu.com/questions/733169/how-to-install-libxml2-in-ubuntu-15-10

sudo apt-get install libxml2-dev

Q4:"An error occurred while installing mysql2 (0.5.2), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.2' --source 'http://gem.wft.int.net.nokia.com/'` succeeds before bundling."

sudo apt-get install libmysqlclient-dev

Q5:“An error occurred while installing rugged (0.27.2), and Bundler cannot continue.
Make sure that `gem install rugged -v '0.27.2' --source 'http://gem.wft.int.net.nokia.com/'` succeeds before bundling.”

sudo apt-get install cmake

最後“bundle install”成功啦

在你的項目文件夾下執行"rails s",等待啓動吧

後面可以根據需要安裝自己的mysql, redis 等,不贅述。

https://www.percona.com/doc/percona-server/LATEST/installation/apt_repo.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章