Skip to content

Instantly share code, notes, and snippets.

@bindiry
Last active August 29, 2015 14:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bindiry/cc4b310cc3047dbb8df6 to your computer and use it in GitHub Desktop.
Save bindiry/cc4b310cc3047dbb8df6 to your computer and use it in GitHub Desktop.
install ROR on Ubuntu 15.04
# 建立用户
$ useradd -m -s /bin/bash bindiry
# 设置sudo权限
$ adduser bindiry sudo
# 设置密码
$ passwd bindiry
# 安装RVM
$ sudo apt-get update
$ sudo apt-get install curl
$ curl -sSL https://get.rvm.io | bash
# 查看当前已知的Ruby版本
$ rvm list known
# 安装ruby,安装过程会请求 apt-get update 的权限,并自动安装系统依赖。
$ rvm use --install --default 2.2.2
# 建立新的gemset
$ rvm use 2.2.2@new_gemset --create --default
# 使用gemset
$ rvm gemset use newgemset
# 查看版本
$ ruby -v
# ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
# 更换Taobao RubyGems镜像
$ gem sources --remove https://rubygems.org/
$ gem sources -a https://ruby.taobao.org/
$ gem sources -l
*** CURRENT SOURCES ***
https://ruby.taobao.org
# 如果使用Bundle
source 'https://ruby.taobao.org/'
gem 'rails', '4.2.1'
# 安装Passenger,首先导入 Passenger 的密钥 (http://www.modrails.com/documentation/Users%20guide%20Nginx.html#install_on_debian_ubuntu)
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
# 安装 apt 插件以支持 https 传输:
$ sudo apt-get install apt-transport-https ca-certificates
# 添加15.04的apt源到sources.list
$ sudo bash -c 'echo "deb https://oss-binaries.phusionpassenger.com/apt/passenger vivid main" > /etc/apt/sources.list.d/passenger.list'
# 或14.04的源
$ sudo bash -c 'echo "deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main" > /etc/apt/sources.list.d/passenger.list'
# 安装 Passenger 的包
$ sudo apt-get install nginx-extras passenger
# 修改 nginx 配置,编辑 /etc/nginx/nginx.conf,找到这两行注释:
# passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
# passenger_ruby /usr/bin/ruby;
# 将它修改为:
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/deploy/.rvm/wrappers/default/ruby;
# 上传文件
# 创建站点文件夹并设置权限
$ sudo mkdir -p /var/www/example.com
$ sudo chown deploy:deploy /var/www/example.com
# git方式clone项目
$ cd /var/www/example.com
$ git clone https://github.com/YOURNAME/REPO.git current
# Install PostgreSQL
$ sudo apt-get install postgresql libpq-dev
# Install MySQL
$ sudo apt-get install mysql-server libmysqlclient-dev
# 执行 bundle 和 migrate
$ cd current
$ bundle install
$ RAILS_ENV=production rake db:create db:migrate
# 执行 assets precompile:
$ rake assets:precompile
# 修改 Nginx 配置
# 删除原有的默认网站配置:
$ rm /etc/nginx/sites-enabled/default
# 新建网站配置:
$ touch /etc/nginx/sites-enabled/example.com.conf
# 编辑 /etc/nginx/sites-enabled/example.com.conf,写入以下内容:
server {
listen 80 default;
server_name example.com; # 这里填写你真实域名
root /var/www/example.com/current/public;
passenger_enabled on;
}
# 重启 nginx:
$ sudo service nginx restart

Install Xcode Command line tool

xcode-select --install

Could not find a JavaScript runtime. 错误

# 到 Gemfile 中解除 gem 'therubyracer', platforms: :ruby 的注释
$ bundle install

mysql 允许root远程访问

# 修改 /etc/mysql/my.cnf
# 将 bind-address = 127.0.0.1 修改为 bind-address  = 0.0.0.0
GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "PASSWORD" WITH GRANT OPTION;
flush privileges;

出现Can't install RMagick 0.0.0. Can't find Magick-config错误的处理

sudo apt-get purge imagemagick libmagickcore-dev libmagickwand-dev
sudo rm -R /usr/include/ImageMagick-6/magick
sudo ln -s /usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16/Magick-config /usr/bin/Magick-config
sudo apt-get install imagemagick libmagickcore-dev libmagickwand-dev

gem install rmagick -v '2.13.3'

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. Can't find the 'libpq-fe.h header 错误

sudo apt-get install libpq-dev
gem install pg

vagrant 使用NFS并设置权限

如果宿主机是linux,则需要安装NFS支持

sudo apt-get install nfs-kernel-server nfs-common 

虚拟机安装NFS支持

sudo apt-get install nfs-common

打开Vagrantfile开启自定义共享

config.vm.synced_folder "/Users/bindiry/workspace", "/home/bindiry/workspace", nfs: "true"

设置宿主机文件夹权限

# 设置可读写
$ sudo chmod o+w /Users/bindiry/workspace
# 设置为非root用户所有
$ sudo chown bindiry:everyone /Users/bindiry/workspace

大功靠成,只是每次启动访问/etc/exports需要密码有点点麻烦。 如果不想输入密码,这里也有解决办法,还提供了脚本,不过要配合这里一起。

让 Vagrant 用户使用 sudo 时不需要输入密码(必须,要不然一些 Vagrant 的功能无法实现)

先输入命令 sudo visudo, 然后在末尾添加一行,内容如下

vagrant ALL=(ALL) NOPASSWD: ALL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment