需要在一个外部的centeros服务器上装ror环境,做开发测试用。过程中又遇到了一些问题。
在网上搜索别人的文章来参考,所以以下内容为多篇文章集合而成。
具体过程:
1. 编译安装ruby
从ruby官网下载目前的稳定版本1.9.3-p0
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz
解压缩
tar -xzvf ruby-1.9.3-p0.tar.gz
进入解压缩后的文件夹
cd ruby-1.9.3-p0
编译安装
./config -prefix=/usr/local/ruby make && make install
设置环境变量
vi /etc/profile后,在文件最后加上
export PATH=/usr/local/ruby/bin:$PATH
保存后,保存后,su -
执行 ruby -v 看是否能输出当前版本。
2. 安装gem
下载gem
wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.zip
解压缩后,进入目录,执行 ruby setup.rb
安装过后更新 gem
gem update --system
gem update
执行gem --version 看是否输出版本号
注意:如果在安装gem的过程中出现如下错误:
/usr/local/ruby/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>': It seems your ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your ruby.
在执行gem --version时出现如下错误:
usr/local/ruby/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>': It seems your ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your ruby. 1.8.24
按照提示所示,就是没有装上libyaml 具体处理的参照了下面这篇文章
http://collectiveidea.com/blog/archives/2011/10/31/install-ruby-193-with-libyaml-on-centos/
具体步骤为先安装libyaml,再重新安装ruby
$ wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz $ tar xzvf yaml-0.1.4.tar.gz $ cd yaml-0.1.4 $ ./configure --prefix=/usr/local $ make $ make install
卸载ruby 直接删除刚刚安装时prefix指定的目录 rm -rf /usr/local/ruby
安装时,需要将之前解压缩的那个目录删掉,重新加压缩ruby的源码压缩包。
$ tar xzvf ruby-1.9.3-p0.tar.gz $ cd ruby-1.9.3-p0 $ ./configure --prefix=/usr/local --enable-shared --disable-install-doc --with-opt-dir=/usr/local $ make $ make install
注意这个地方的./configure --with-opt-dir=/usr/local 文章里写的是--with-opt-dir=/usr/local/lib 下面有个评论回复到:
Thanks for the useful tip. I found that instead of
—with-opt-dir=/usr/local/lib
I need to run ./configure with
—with-opt-dir=/usr/local
(without the lib). Otherwise, strace shows the loader trying to load the libyaml library from /usr/local/lib/lib.
所以去掉lib,安装成功。
然后再执行一边gem的安装步骤,不出意外的话不会再有yaml的提醒,安装成功后查看版本也不再有提示。
3. 安装rails
gem install rails rails --version
4. 测试blog
rails new blog
cd blog rails server
如果启动server时出现以下错误:
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable) from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
因为缺少 JavaScript的服务器解释引擎导致的
下面这篇文章为Ubuntu下使用no v8de.js引擎的安装方法
http://blog.ibuo.org/index.php/2012/05/25/ubuntu-install-rails/
我没有用v8,尝试
gem install execjs
gem install therubyracer
还是没有成功,所以就参照如下文章装了node.js
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
centeros选择了中间的那部分安装命令
wget http://nodejs.tchol.org/repocfg/el/nodejs-stable-release.noarch.rpm yum localinstall --nogpgcheck nodejs-stable-release.noarch.rpm yum install nodejs-compat-symlinks npm
再运行 rails server 。。。久违的成功。
[root@play blog]# rails server => Booting WEBrick => Rails 3.2.6 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2012-07-03 18:15:32] INFO WEBrick 1.3.1 [2012-07-03 18:15:32] INFO ruby 1.9.3 (2011-10-30) [x86_64-linux] [2012-07-03 18:15:32] INFO WEBrick::HTTPServer#start: pid=21057 port=3000
访问 http://serverip:3000 即可打开欢迎页面
再次感慨下:每次安装,别人遇到的问题自己都会重复。。人品啊