Use RVM to install ruby & rails in ubuntu

Source: Internet
Author: User

Use RVM to install ruby & rails in ubuntu

 

I have discussed how to install ruby in the source code mode in ubuntu. However, this method is always troublesome. You can use rvm for version management, and you can also use rvm for installation. linux exclusive tools, haha, installing rvm in linux is also a command, but before that, we need to install some other software to ensure that the program can be installed,

bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )

First, installing rvm should be used for curl and git to obtain and install the rvm. First, ensure that the rvm can be installed, and then it will be used in the future, as well as many compilation tools, A large number of dependency packages, a one-time solution, and the following command

sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g
zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf

No problem. If the software has been installed, it will be automatically updated. If the latest version is already installed, it will automatically jump over. Therefore, you don't have to worry about repeated installation. Since the above tools have been installed run the first command again. Remember not to use sudo for installation. If you use sudo for installation, rvm will be installed under the root user, so all rvm settings are available. we need to install rvm Based on root, so we should not use sudo to install rvm. If you want to use rvm for both root and current users, the problem has already involved multiple users to install rvm. Now, this problem should be put aside for the moment. first,

 

Then rvm has been installed, but you cannot directly use the rvm command at any location through the terminal, so we first add rvm to the linux shell Command, first enter the user directory, simple input cd ~ You can use any tool to edit the. bash_profile file. You can use vi, gedit, and input commands.

vi .bash_profile

If the current directory is not a user directory and the command is changed

vi ~/.bash_profile

In this way, you can modify this file anywhere, and then add a row at the bottom.

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

Save it, and then execute source. bash_profile: Enter rvm-v on the terminal. If you see the rvm version information, the installation is successful. if bash_profile doesn't work, try clearing it. modify the bash_profile file to this sentence.

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM function

Of course, they are all executed in the user directory, but not in the user directory ~ /. Bash_profile

++

Note: This is the official RVM installation method, but each linux release version is different! In ubuntu, there is no. of course, you can create a new bash_profile file. bash_profile adds this statement again, but this will cause problems. For example, it will lead to the failure of ll commands and other strange things. Please pay attention !!! In the ubuntu user's home directory,. profile is the general linux version. bash_profile, so the above operations should be changed to the. profile file if they are installed in ubuntu !!

++

After rvm is installed, the rest is quite simple. First, 1.9.2 is installed, which is now the most suitable, although 1.9.3 has been installed.

Execute Command

rvm install 1.9.2

If you want to install other versions, you need to modify the format and install ruby1.9.2. The fact is that rvm is a multi-version management tool. Remember this. it's okay to install 1.8.7 and 1.9.3. The problem is how to switch back to 1.9.2. You can use this command,

rvm use 1.9.2

In this way, you can switch back to 1.9.2 at any time, but as long as you close this terminal or start a new terminal, you have to re-execute this command again, so you can execute the following command to make the reality permanent switch

rvm use 1.9.2 --default

OK. You can use ruby-v or gem-v to check whether ruby is installed, and then use gem install rails as usual to install rails smoothly,

 

One thing to note is that we have just installed rvm as a single user, so it is forbidden to create a rails project in a system partition or a place that is not accessible by the current user. this is because rvm is only installed on the current user, so you can only use sudo to temporarily call the root permission to establish a non-Permission range. for the root user, rvm is not installed. This time, you have the permission but cannot use the rails command. Therefore, if you install rvm by a single user, the rails project can only be set to a directory within the current user's permission range. Recommended user directory

 

 

P.S.: some students may report errors when executing gem install rails and lack zlib. This may be because the dependency package is not installed when ruby is installed, and it is estimated that the package is broken by the wall, so we execute

rvm pkg install zlib

If an error is still reported, it should be that the network cannot be crawled, the network is blocked, and =. =. At this time, you need to put the zlib package in the local directory. rvm/archives (if you install it in the form of multiple users, it is located under/usr/local/rvm/archives) and then execute this command. In the future, you need to download the offline package to the archives directory and then uninstall the original ruby1.9.2 if you cannot directly install the rvm pkg install command on the network. run the following command to install the dependent package.

 rvm remove 1.9.2
rvm install 1.9.2 --with-zlib-dir=$rvm_path/usr

Similar problems include openssl. When rails s is started, an error will also be reported. openssl must be installed on rvm, and then -- with-openssl-dir, during installation, pkg zlib, pkg openssl, pkg, and then rvm install 1.9.2 -- with-zlib-dir = $ rvm_path/usr -- with-openssl-dir = $ rvm_path/usr.

P.S. 2: It is really hard to install rails in linux. If you encounter a startup error or sqlite3 error when starting rails s! An error occured while installing sqlite3 (1.3.4), and Bundler cannot continue.
Make sure that 'gem install sqlite3-v '1. 3.4 ''succeeds before bundling.
Run the following command:

apt-get install libsqlite3-dev

Then you can go to the directory and use rails to start the server. By the way, you must add a Javascript parser to the Gemfile file for newly started rails projects.

gem 'execjs'
gem 'therubyracer'

Then, run the bundle install command in the root directory of the project.

If you want to use the postpgsql database in rails, you only need to add gem 'pg 'to Gemfile and then execute bundle install,

If an error is reported

Building native extensions. This cocould take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.

You can install the following components.

sudo apt-get install libpq-dev

 

The preceding method is used to install rvm by a single user. If you want to install multiple users, you must install rvm by using sudo instead of the root user.

sudo bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )

 

P.S.: before you decide to use the multi-user Method for installation, make sure that you already have the root user, or modify the/etc/sudoers file first. Otherwise, the sudo command will make you want to cry

 

In this way, the rvm will be installed to the/usr/local/rvm directory, instead of ~ /. Rvm/directory, and an initial loaded shell will be generated in/etc/profile. d/rvm. sh,

Then add the user to the rvm group, for example, klobohyz,

sudo usermod -G rvm klobohyz

This is OK, but it is not available yet. You must log out first and then log in to use it. In this way, you can use the rvm command. Note that you do not need to switch other users after logging in. Otherwise, rvm it will expire. At this time, You need to log on to the user again. If the user cannot use the sudo command again after you log on again, please refer to this article: http://www.cnblogs.com/klobohyz/archive/2011/12/22/2297392.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.