mac系统回退到El Capitan,各种环境都要重新搭建,Scala的环境搭建与Java环境的搭建类似,而ruby环境的搭建坑就比较多。
听说在Ubuntu上搭建ruby环境坑会少点。
0.首先,mac需要安装xcode,它将帮你安装好Unix环境需要的开发包。
安装xcode注意os的版本,高版本的xcode对低版本的os是不兼容的
1.安装homebrew和rvm
安装homebrew就不细说,参考https://brew.sh/index_zh-cn.html
安装rvm:
$ curl -L https://get.rvm.io | bash -s stable
需要一段时间进行安装,安装好了之后check下版本:
$ rvm -v
一般安装rvm没有什么问题,只要注意下安装的版本是不是正确的,正常安装最新版本的或者是次最新的版本。
2.使用rvm安装ruby环境
查询出已有的ruby版本:
$ rvm list known
选择一个版本进行安装:
$ rvm install 2.2.4
等待安装编译完成,check下安装:$ rvm list
3.简单设置下ruby
主要是由于某位教授的原因,导致需要梯子,所以需要切换下source,国内比较稳定好用的source就是淘宝的,所以讲gem source从默认的rubygems.org切换到ruby.taobao.org
$ gem source -r http://rubygems.org/
$ gem source -a http://ruby.taobao.org/
check下结果:
$ gem source -l
到这里基本的ruby开发环境搭建起来了
4.安装bundle,通过bundle运行项目
安装bundle:gem install bundler //默认安装最新的版本
有了bundle工具,就可以bundle install了,这里根据GemFile来进行install,这里有几个比较坑的问题:
a.关于thrift-0.9.1.gem,在安装这个gem的时候会报如下的错:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/Users/shangliang/.rvm/rubies/ruby-2.1.5/bin/ruby -r ./siteconf20160520-20541-1undjkx.rb extconf.rb
checking for strlcpy() in string.h... yes
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling binary_protocol_accelerated.c
compiling compact_protocol.c
compiling memory_buffer.c
compiling protocol.c
compiling strlcpy.c
In file included from strlcpy.c:20:
./strlcpy.h:28:15: error: expected parameter declarator
extern size_t strlcpy(char *, const char *, size_t);
.............
解决办法:https://github.com/instructure/canvas-lms/issues/827
b.在安装mysql相关的gem,需要提前通过homebrew安装mysql-client
(暂时只想起这两个比较坑的,剩下的以后碰到了再补充)