Installing Rails on CentOS 5

Note: Since this post originally went up, some of the packages have changed/updated. I’ve kept things pretty well up-to-date, but you might want to double check the latest versions and alter the bash commands accordingly. Be aware that as of this writing, the Ruby team has made 1.9.1 the latest stable and only Rails itself is deemed compatible with Ruby 1.9x. I.e., Rails passes all its own tests on 1.9.1, but most plugins, libraries, etc are likely to give you problems right now. So your best bet is to use 1.8.7 for awhile until your favorite libraries jump on board the 1.9 wagon.       –Trevor (August 17, 2009)

I recently had to roll a new VM for work in order to run Rails and Sinatra apps on Apache/Passenger . My company favors CentOS as the default distro for all our boxes, so I wasn’t able to use all the super-up-to-date packages that Ubuntu makes available, and I ended up building everything from source. For posterity and for anyone else who needs it, here’s a list of what to do and how to do it.

Dependencies

You’ll need several libraries and the MySQL server, and you can use yum to install them all at once. This set includes the gcc compiler, the gcc-c++ compiler, and the zlib development headers for Ruby. Remember: not all libraries are the same — you’re going to need to make sure that you’re compiling Ruby w/ 32 or 64-bit development headers as appropriate for your architecture.

1
2
3
4
5
6
7
8
9
10
sudo yum install httpd-devel\
  openssl-devel\
  zlib-devel\
  gcc\
  gcc-c++\
  curl-devel\
  expat-devel\
  gettext-devel\
  mysql-server\
  mysql-devel

Ruby

Next up is Ruby. We’ll install 1.8.7-p72, the latest stable as of this writing. First, we’ll make a “src” directory in /usr/local to hold everything:

1
2
3
4
5
6
7
8
sudo mkdir /usr/local/src
  cd /usr/local/src
  sudo curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
  sudo tar xzvf ruby-1.8.7-p72.tar.gz
  cd ruby-1.8.7-p72
  sudo ./configure --enable-shared --enable-pthread
  sudo make
  sudo make install

Ok now for a weird thing — you need to remake and re-install Ruby after using it to run a script that helps you make a new makefile. This is so that you can tell it where the zlib headers live:

1
2
3
4
5
cd ext/zlib
  ruby extconf.rb --with-zlib-include=/usr/include --with-zlib-lib=/usr/lib
  cd ../../
  sudo make
  sudo make install

After all that happens, you should have Ruby installed. Check and see by doing:

1
ruby --version

You should see something like:

1
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-linux]

Rubygems

Now that you have Ruby installed, Rubygems is easy — the whole thing is in Ruby so there’s nothing to build/compile.

1
2
3
4
5
cd /usr/local/src
  sudo wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
  sudo tar xzvf rubygems-1.3.5.tgz
  cd rubygems-1.3.5.tgz
  sudo ruby setup.rb

Rails, Passenger, MySQL and Sinatra

Now that Ruby and Rubygems are installed, you can install Rails, Passenger, and Sinatra as gems:

1
sudo gem install rails passenger sinatra

That will take awhile, as there’s a ton of documentation to build for Rails, and Passenger has to compile some native extensions.

Once that’s done, finish the Passenger installation with their nifty installer tool:

1
sudo passenger-install-apache2-module

Follow the provided instructions at the end of the installer for adding lines to httpd.conf:

1
2
3
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.6
PassengerRuby /usr/local/bin/ruby

After that, install the MySQL gem, making sure to specify where the config is:

1
sudo gem install mysql -- --with-mysql-config=/usr/bin/mysql_config

Disabling SEL inux

The RedHat family of distros (RHEL, CentOS, Fedora) come with SEL inux enabled by default. If you want to learn how to make it work with Passenger, you can try this tip from the Passenger user’s guide. I just turned it off because the box is only going to be used for these apps, and SEL inux seems like overkill. Here’s how to shut it down:

First, disable it temporarily:

1
sudo echo 0 >/selinux/enforce

That’s not a permanent fix though, because the next time the server boots, it’ll be turned back on again. You need to edit the config file and turn it off. Open it with your favorite editor and change one line. You need to be root or running as sudo to edit this file, and I prefer Vim when on remote servers, so it’s:

1
sudo vim /etc/sysconfig/selinux

Change this:

1
SELINUX=enforcing

to this:

1
SELINUX=disabled

Restart Apache

You should be able to restart Apache now and have Passenger come up no problem. There are several ways to restart Apache, but I like to use the service way to keep it simple:

1
sudo /sbin/service httpd restart

Optional: Installing Git

For SCM, there are a lot of reasons why I like Git better than Subversion. It’s got a bit of a learning curve, but once you go Git, you never go back.

1
2
3
4
5
6
cd /usr/local/src
curl -O http://www.kernel.org/pub/software/scm/git/git-1.6.0.4.tar.gz
tar zxf git-1.6.0.4.tar.gz
cd git-1.6.0.4.tar.gz
sudo make all
sudo make install

And the man pages:

1
2
3
4
cd /usr/local/src
curl -O http://www.kernel.org/pub/software/scm/git/git-manpages-1.6.0.4.tar.gz
cd /usr/local/share/man
tar -zxf /usr/local/src/git-manpages-1.6.0.4.tar.gz

Now you should have Git installed and ready. Prove it:

1
git --version

You should see something like:

1
git version 1.6.0.4

And that’s it — you now have a full Ruby stack ready to go on CentOS 5. Much of this tutorial was adapted from the awesome Hivelogic post on installing the stack on OS X Leopard.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值