Build Ruby on Rails in Ubuntu
Ruby on Rails is an open-source Web framework written in ruby., Similar to J2EE and PHP. Ruby on Rails is a very beautiful web development framework and incorporates the essence of agile development:Conventions greater than configurations. You will find that it is really a very beautiful framework! Today we will introduce how to build Ruby in Ubuntu
On Rails development environment.
1.
Since Ruby on Rails is written in the ruby language, we shouldFirst install Ruby, Download the source code in the official website http://rubyonrails.org. The official website includes all the tools from scratch to build a complete Ruby on Rails development environment.Ruby-1.9.3-20.tar.gz
2.
Unzip and install:
./Configure -- prefix =/usr/local -- enable-shared -- disable-install-doc -- With-opt-Dir =/usr/local/lib
Make
Sudo make install
3.
Enter at the terminal:Ruby-V should output the ruby version number if the installation is correct., As shown below:
4.
Below we will write a hello World in ruby:
NewTest. RbFile, enter the following content:
# Simple testputs 'hello, world!'puts 2*3
# In Ruby indicates that the row is an annotation, And the puts function indicates that a string is output.
Enter the following information on the terminal:
Ruby-W test. Rb
-W indicates that a warning is given during execution.
The result is as follows:
Now, we have set up the ruby environment. If you only want to learn the ruby language, you can do it here.
5.
Install Ruby on Rails:
Sudo gem install rails
This step is very time-consuming. It will take about 1 hour for me to get a good network speed.
If a problem occurs in the middle, retry again and again! That's what I do.
The result after installation is as follows:
If an error similar to "installing Ri documentation for rails-3.2.3... file 'lib 'not found" occurs, run the following command:
Gem install rdoc
In addition, several common errors and solutions are provided at the end of this article.
After rails is installed, enterGem-VAndRails-VCheck as follows:
In this way, the Ruby on Rails development environment is ready. Alas ~ So tired !!!
6.
The following is an example of getting started on the official website:
Http://guides.rubyonrails.org/getting_started.html
Mkdir Test
CD Test
Rails new blog
A blog folder will be created under the current directory test, which is our web root directory:
During creation, you must enter the sudo password:
It takes about 5 minutes to create the instance, for example:
7.
Create a sqlite3 database:
CD blog
Rake DB: Create
8.
Finally, we start the server. rails has a built-in webrick Web Server:
Rails Server
For example:
9.
Enter http: // localhost: 3000/in the browser, for example, haha. Our Ruby on Rails development environment has finally been set up. It's so tiring!
Common problems and solutions:
1.
InRails new blogPrompt:
The reason is that libyaml is not installed. solution:
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
Sudo make install
Then reinstall Ruby (step 1 above)
2.
InRails new blogPrompt:
This is because a writable directory is included in the path directory of the system, which may cause potential risks. solution:
Sudo chmod go-W/opt/Skyeye/bin
Note: The Directory here will be different, but the error principle is the same.
3.
Rake DB: CreatePrompt:
Solution: Install node. JS:
Sudo apt-Get install nodejs
Done!