Category Archives: Ruby

Error installing rmagick on Ubuntu

While running bundle install I am getting this error:

$ gem install rmagick Building native extensions. This could take a while...

ERROR: Error installing rmagick: ERROR: Failed to build gem native extension. Can't install RMagick 2.13.2. Can't find Magick-config

I have solve this problem by installing rmagick and libmagick++-dev package

Install imagemagick:

sudo apt-get install imagemagick

Install rmagick:

$ sudo apt-get install libmagick++-dev
Advertisements

Install Ruby on Rails in Ubuntu 14.04 LTS

Here is step by step instruction on how to set up ruby on rails in ubuntu 14.04 LTS

Installing Ruby using RVM:

First you have  to install  some dependencies for Ruby.

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev

Now install ruby with RVM using those commends:

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
rvm install 2.1.1
rvm use 2.1.1 --default
ruby -v

Installing Rails:

Rails comes with so many dependencies like NodeJS

To install NodeJS, we’re going to add it using a PPA repository:

sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

Now run for install rails:

gem install rails
rails -v
# Rails 4.1.0

Setting Up MySQL:

You can install MySQL server and client from the packages in the Ubuntu repository.

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

Setting Up PostgreSQL:

For PostgreSQL, you need to add a new repository to easily install a recent version of Postgres 9.3.

sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.3 libpq-dev

For postgres you need to set up a user.

sudo -u postgres createuser chris -s
# If you would like to set a password for the user, you can do the following
sudo -u postgres psql
postgres=# \password salayhin

Test your settings for new install:

#### If you want to use MySQL
rails new new_app -d mysql

#### If you want to use Postgres
rails new new_app -d postgresql

# Move into the application directory
cd new_app

# If you setup MySQL or Postgres with a username/password, modify the
# config/database.yml file to contain the username/password that you specified

# Create the database
rake db:create

rails server

All done. Now visit http://localhost:3000 to view your new application.

Enjoy. Happy Coding 🙂

Upgrade to Ruby 2.0.0-x

To upgrade your ruby version follow those steps.

First run the following commands:

rvm get head

followed by:

rvm requirements

If you don’t get any errors you can run:

rvm install 2.0.0-x

To set as your current version of Ruby run the following command:

rvm use 2.0.0-x

To make it the default Ruby:

rvm default 2.0.0-x

Or you can run single command for both use and set default:

rvm use 2.0.0-x --default

Now ruby 2.0.0-x is the default version. To check ruby version run:

ruby -v

and where it’s located executing the command:

which ruby

That’s it. Happy coding 🙂