This guide will go through installing the RVM (Ruby Version Manager), then a version of Ruby (1.9.3), then Rails and finally Bundler, and is specifically written for a development environment on Debian based systems.
Under no circumstance should you install Ruby, Rubygems or any Ruby-related packages from apt-get. This system is out-dated and leads to major headaches. Avoid it for Ruby-related packages.
We do Ruby, we know what's best. Trust us.
First of all, we’re going to run sudo apt-get update
so that we have the latest sources on our box so that we don’t run into any package-related issues, such as not being able to install some packages.
Next, we’re going to install git
(a version control system) and curl
which are both required to install and use RVM, and build-essential
which is required to compile Ruby versions, amongst other compilable things. To install these three packages we use this command:
sudo apt-get install curl
RVM is a Ruby Version Manager created by Wayne E. Seguin and is extremely helpful for installing and managing many different versions of Ruby all at once. Sometimes you could be working on a project that requires an older (1.8.7) version of Ruby but also need a new version (1.9.3) for one of your newer projects. This is a problem that RVM solves beautifully.
Another situation could be that you want to have different sets of gems on the same version of Ruby but don’t want to have to do deal with Gem Conflict Hell. RVM has gemsets for this. This is a feature you wouldn't have if you used the packaged Ruby.
We’re going to use it to install only one version of Ruby, but we can consult the documentation if we want to install a different version of Ruby.
With curl installed we’ll be able to install RVM with this command:
curl -L get.rvm.io | bash -s stable --auto
The beautiful part of this is that it installs RVM and Ruby to our home directory, providing a sandboxed environment just for us.
Then we’ll need to reload the ~/.bash_profile
file which we can do with this small command:
. ~/.bash_profile
The next command we run will tell us what other packages we need to install for Ruby to work:
rvm requirements
...
# For Ruby / Ruby HEAD (MRI, Rubinius, & REE), install the following:
ruby: /usr/bin/apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkgconfig
A couple of these packages we’ve already installed, such as git-core
and curl
. They won’t be re-installed again.
These packages will lessen the pain when we’re working with Ruby. For example, the libssl-dev
package will make OpenSSL support in Ruby work, libsqlite3-0
and libsqlite3-dev
are required for the sqlite3-ruby gem and the libxml2-dev
and libxslt-dev
packages are required for the nokogiri gem. Let’s install all these packages now using this command:
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev \
curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 \
libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison \
subversion pkgconfig
Now our Ruby lives will be as painless as possible.
With RVM and these packages we can now install Ruby 1.9.3:
rvm install 1.9.3
This command will take a couple of minutes, so grab your $DRINKOFCHOICE and go outside or something. Once it’s done, we’ll have Ruby 1.9.3 installed. To begin using it we can use this lovely command:
rvm use 1.9.3
Using ‘1.9.3’ as a default allows for when ruby is updated for that version then ALL projects using 1.9.3 as their string will be updated as well. This is a side affect people might not want. The preferred method is to include the patch level to the ’–default’ parameter so that if 1.9.3 gets updated, other projects don’t automatically have that change applied to to them as well. If, say for example, for some reason some method/action gets deprecated in a patchlevel or some method signature gets changed between patchlevels, this will affect all projects defined using the ‘1.9.3’ string. This may or may not be what people want. Please be aware of this! Now, to continue on..
Are we using 1.9.3? You betcha:
ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
Or, even better, would be to make this the default for our user! Oooh, yes! Noting the ‘1.9.3’ side-note above, lets take note of the patchlevel, which in this case is ‘-p194’ and add that to our default selection.
rvm --default use 1.9.3-p194
Now whenever we open a new bash session for this user we’ll have Ruby available for us to use! Yay!
Users can, and should, use a gemset when possible so that they don’t pollute their ‘default’ which is what is selected when a gemset is not specified in either a project’s .rvmrc, or at the command-line. Each installed Ruby has a ‘@global’ gemset. This is used to share gems with other gemsets created under that specific Ruby, and with the ‘default’ gemset. This can be selected by running ‘rvm gemset use global’ and then installing the gems you wish to share to other gemsets including ‘default’. You can, of course simply install in each gemset but this will cause needless duplication and use up more disk-space and bandwidth.
rvm gemset create myGemset
rvm gemset use myGemset
or you can switch with
rvm use 1.9.3-head@myGemset
you can also specify a default gemset for a given ruby interpreter, by doing:
rvm use 1.9.3-head@myGemset --default
######tip
If you don't want to wait around for rdoc and ri docs to install for each gem, just add these two lines to your ~/.gemrc
or /etc/gemrc
:
install: --no-rdoc --no-ri
update: --no-rdoc --no-ri
Now that RVM and a version of Ruby is installed, we can install Rails. Because RVM is installed to our home directory, we don’t need to use that nasty sudo to install things; we’ve got write-access! To install the Rails gem we’ll run this command:
gem install rails -v 3.2.8
This will install the rails gem and the other 28 gems that it and its dependencies depend on, including Bundler
.
If you’re planning on using the mysql2
gem for your application then you’ll want to install the libmysqlclient-dev
package before you do that. Without it, you’ll get an error when the gem tries to compile its native extensions:
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/home/ryan/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
#TODO
Similar to the mysql2
gem’s error above, you’ll also get an error with the pg
gem if you don’t have the libpq-dev
package installed you’ll get this error:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/ryan/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb
checking for pg_config... no
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
######note Installing via packet manager don't work for me, there is some strange error when i want to connect shell to db. Do it 'manual' way.
-
Head over to the official download page and grab the binaries.
-
Extract the archive and navigate to the
bin
subfolder,mongod
is the server process andmongo
is the client shell. -
Create a new text file in the
bin
subfolder namedmongodb.config
-
Add a single line to your mongodb.config:
dbpath=PATH_TO_DATABASE_FILES
. Defaultdbpath=/data/db
,create it and make sure that you have privileges on it. -
Make sure the
dbpath
you specified exists -
Launch mongod with the
mongod --config /path/to/mongodb.config
.
You can now launch mongo
(without the d) which will connect a JavaScript shell to your running server.
Install the gem:
gem install mongo
The required bson
gem will be installed automatically.
For optimum performance, install the bson_ext
gem:
gem install bson_ext
As long it's in Ruby's load path, bson_ext
will be loaded automatically when you require bson
.
This is slightly modified version of @ryanbigg's article http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/ just in case,if some servers stop working :)
Hello,
It seems that you install ruby on a user that is in sudoers group - am i right?
I want to install ruby with rvm on a user that has no sudo-privileges. Is this possible?
Best Regards,
Christian