Install Ruby On Rails on CentOS
Assumption:
- CentOS 6 X64
- Ruby 1.9.2
- Rails 3.1.0
Steps:
- Preinstall the dependencies if they are not installed yet
yum install httpd-devel openssl-devel zlib-devel gcc gcc-c++ curl-devel expat-devel gettext-devel mysql-server mysql-devel
- Download and install Ruby
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p180.tar.gz
tar -xvzf ruby-1.9.2-p180.tar.gz
cd ruby-1.9.2-p180
./configure
make
make install
- Alternative way to install ruby, by RVM,( highly recommended):
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
source ~/.bash_profile
rvm install 1.9.2
rvm use 1.9.2 --default
- Download and install RubyGems
wget http://rubyforge.org/frs/download.php/74954/rubygems-1.8.5.tgz
tar -xvzf rubygems-1.8.5.tgz
cd rubygems-1.8.5
ruby setup.rb
Gem actually will be installed with ruby 1.9.2, so simply use following to update itself:
gem update --system
Use gem-fast to boost gem installation speed, with progress indicator addded (Experemental):
gem install gem-fast
If you have having "zlib" related issues with gems command, try following:
cd ruby-1.9.2-p180/ext/zlib
ruby extconf.rb
make
make install
- Install Rails
gem install rails
- Bundle Insall
If you are having issue on "`require': no such file to load -- openssl", you have to install openssl-devel, do following:
sudo apt-get install openssl libssl-dev
cd /ruby_install_dir/ext/openssl
ruby extconf.rb
make
make install
For installing rmagick, you might also need to install ImageMagick-devel by yum first:
yum install ImageMagick
yum install ImageMagick-devel
Setup ROR on centos
- Getting following error while try to start passenger in app directory:
Cannot execute '/var/lib/passenger-standalone/3.0.7-x86_64-ruby1.9.2-linux-gcc4.1.2-1002/support/helper-scripts/prespawn http://0.0.0.0:3000': Permission denied (13)
Solution: Change the permission of that file to 755 did solve the problem.
- Getting error while try to install gems by "bundle install"
Solution: Use "bundle check" to check the missing gems, and use "gem install" to install them
Rails installation
Setup rails edge with edge rDoc:
gem install rails --rdoc -v ">=3.1.0rc"
Envioronment
Specifying environment for rake command:
Simply add RAILS_ENV=test before the rake command.
Bundle command
# Install missing gems
bundle install
# Update gems
bundle update
如果不能安装linecache19 (0.5.12)
gem install ruby-debug19 -- --with-ruby-include=$rvm_path/src/ruby-1.9.2-p290
远程发布站点:
如果发生错误--- bundle command not found
在~/.bashrc文件中加入代码
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
在gemfile中加入代码
gem 'execjs'
gem 'therubyracer'
Documentations
Running following command to generate rails API document under doc/api:
rake doc:rails
Another way,
gem server
Then, access the created web server for accessing all rDOC informations.
install apache+passenger
1.install Passenger
gem install passenger --include-dependencies
passenger-install-apache2-module
2.config apache /etc/httpd/conf/httpd.conf
Passenger will also suggests how to modify HTTPD. Conf configuration files
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.9
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.2-p290/ruby
<VirtualHost *:80>
ServerName www.depot.com
DocumentRoot /var/www/railswork/depot/public #指向public目录
<Directory /var/www/railswork/depot/public>
AllowOverride all
Options Indexes -MultiViews
</Directory>
</VirtualHost>
3.restart apache
4. # /etc/init.d/httpd restart
Stopping httpd: [FAILED]
Starting httpd: httpd: Syntax error on line 210 of /etc/httpd/conf/httpd.conf: Syntax error on line 1 of /etc/httpd/conf.d/ruby.conf: <br>Cannot load /usr/local/ruby/lib/ruby/gems/1.8/gems/passenger-.0.0.pre2/ext/apache2/mod_passenger.so into server: /usr/local/ruby/lib/ruby/gems/1.8/gems<br>/passenger-3.0.0.pre2/ext/apache2/mod_passenger.so: failed to map segment from shared object: Permission denied
run command:
# chcon -R -h -t httpd_sys_script_exec_t /usr/local/ruby/lib/ruby/gems/1.8/gems/passenger-3.0.0.pre2/ext/apache2/mod_passenger.so
5.restart apache
sudo service httpd restart