I’ve always heard that rubyonrails is very efficient, so I tried it a while ago, and now I’m reviewing it rails Environment Building process. I am using ubuntu14.04LTS. After reading various posts and some tutorials on the Internet, it seems that it is not recommended to do it under windows rails development, generally linux and macos .
preliminary work
during installation railsBefore the environment, there are some necessary The package needs to be installed to avoid various missing library problems in subsequent installations (see http://ihower.tw/rails3/). Execute the following instructions:
$sudo apt-get install build-essential bison openssl libreadline6libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-devlibyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-devlibxslt-dev autoconf libc6-dev
When installed using apt-get Sometimes you encounter unableto The problem of locate can generally be solved by updating:
$sudo apt-get update
If update cannot be executed either, "isthe" appears Internet authenticated?" and other prompts, it is likely that the network is limited. I discovered this problem when using the hotel's network...
RVMInstallation
RVM is a command line tool that provides A convenient multi-version rubyenvironment management and switching, which can bring great convenience to you learning ruby/rails Of course, you don’t have to use it . rvm, but I personally prefer to use rvm.
To install rvm you need to use curl, which has already been installed. Then follow rvm Official website instructions for installation , very simple, just execute two commands:
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
$ curl -sSL https:/ /get.rvm.io | bash -sstable
After installation is complete, run: $source ~/.rvm/scripts/rvm
This completes the installation of rvm. It can be run by running $ rvm -v to check if rvm is installed successfully.
Install with rvmruby
Run $rvm install 2.0.0 to install ruby2.0.0 version. You can install the corresponding version according to your needs. If Errorrunning occurs 'requirements_debian...' error, you can run $rvm autolibs disable first and then install it. If all the packages have been installed in step 1, then the installation should be successful here, otherwise the error missingxxx will appear.
Ruby version settings
RVM can be used to install multiple versions ruby, so if the same If there are multiple versions of ruby installed on a computer, you need to specify which version of ruby to use. Available$rvm 2.0.0 --default command to specify the default version (here is the 2.0.0 version).
Attention, for ubuntuitsterminalreal gnome-terminal, so it will appear RVMis not a function error, you need to open the terminalEdit->profile->preferences->Titleand Command,selectRun command as a loginshell. Close the terminal and reopen the terminal to run the rubyversion setting command. For details, please see: https://rvm.io/integration/gnome-terminal
rails
rails, you can install the RVMRuby to the domestic Taobao Mirror Like serverhttp://ruby .taobao.org/, otherwise it will not respond for a long time and cannot be installed:
$gemsources --remove https://rubygems.org/
$gemsources -a https://ruby.taobao.org/
$gemsource s -l
***CURRENT SOURCES ***
Use
rvm Set accordingly ruby/rails of gemset. If we want to use the 2.0.0 version of ruby and the 4.1.8 version of rails carried out combination, you can set a gemset environment for it. The specific operations are as follows: $rvm use 2.0.0
(using 2.0.0 version of ruby) $rvm gemset create rails418
(Create a named rails418 gemset, the name can be arbitrary) $gem install rails [--version=' 4.1.8'] (Install rails, the following version parameter is optional, if not filled in, the latest version of will be installed rails. If it appears during installationunableto.
For errors such as convert "/x89" from ASCII to UTF8, you can run $gem install rdoc and $gem
rdoc --all --overwrite to solve) $rvm use 2.0.0@rails418 –default(will ruby2.0.0 and rails4.1.8 combined gemset as the default gemset) can be used$rvm gemset list to see which gemsetenvironments you have set, the same, $rvm
list can check which versions of ruby are installed. We may ask, if I have multiple rails projects, each project requires a different environment, then I need to switch manually every time I switch projects gemsetenvironment? In fact, we can create a .rvmrc file in the root directory of each project, and write in it for example rvmuse
2.0.0 @rails418 command to specify the gemset environment used. In this way, every time we enter this directory, we will switch to this environment. Deployment of Rails passenger is a webapp
server, nginx is a high-performance HTTP and reverse proxy server. There are actually several software available for deployment, and you can choose by yourself. First install passenger: $gem
After install passenger, use the rvmsudo command to install the module with passenger nginx: $ rvmsudopassenger-install-nginx-moduleThis waynginx The default installation path is /opt/nginx , modify /opt/ nginx/conf/nginx.conf file to specify the root directory as the rails project's public directory. Then start nginx:$ sudo /opt/nginx/sbin/nginxThis way you can use your own rails Project . Using this method to install passenger is very convenient. Nginx is not like apache, apacheWhen a module is needed, you only need to add the module to the configuration file and restart. However, nginx can only be compiled and installed after configuring the required modules. Once the installation is completed, no more modules can be added. So if you want to install it separately, you need to go online to check how to configure nginx and passenger. For separate installation, how to configure nginx so that it can support passenger, here is the official reference document address of passenger: https://www.phusionpassenger.com/documentation/UsersguideNginx.htmlAs for how to add nginx to the service and start it up, the following is givenhttp:// A script on www.nginx.cn/204.html: #!/bin/sh
DESC="nginxdaemon"
NAME=nginx DAEMON=/opt/nginx/sbin/$NAME CONFIGFILE=/opt/nginx/conf/$NAME.conf PIDFILE=/opt/nginx/ logs/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME set -e
[-x "$DAEMON" ] || exit 0
do_start(){
$DAEMON -c $CONFIGFILE || echo-n "nginx already running"
} do_stop(){
kill -INT `cat $PIDFILE` ||echo -n "nginx not running"
} do_reload(){
kill -HUP `cat $PIDFILE` ||echo -n "nginx can't reload"
} case "$1" in
start)
echo -n "Starting $DESC:$NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC:$NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESCconfiguration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting$DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME{start|stop|reload|restart}" >&2
exit 3
;;
esac exit0 Save this script as a new file /etc/init.d/nginx and you can use it later sudoservice
nginx start/stop/restart to operatenginx service. Given below is how to uninstall ruby, Instructions for gemset: Uninstall a ruby Version: $rvm
remove 2.0.0 Clear a gemset of the used gem, and want to reinstall all gem: $rvm gemset empty 2.0.0 @rails418 Delete a gemset : $rvm
gemset delete rails418
The above introduces the environment construction of Ruby on rails, Passenger and Nginx under Ubuntu 14.04, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.