Category Archives: Ruby

Installing Ruby and Rails with rbenv in Fedora 27

Screenshot from 2018-03-09 03-51-01

The first step is to install dependencies for Ruby.

sudo dnf install git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel

Install rbenv

cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

Install Ruby

rbenv install 2.5.0
rbenv global 2.5.0
ruby -v

Use this command if you do not want rubygems to install the documentation for each package locally.

echo "gem: --no-ri --no-rdoc" > ~/.gemrc

Install bundler

gem install bundler

Whenever you install a new version of Ruby or a gem, you should run the rehash sub-command. This will make rails executables known to rbenv, which will allow us to run those executables:

rbenv rehash 

Installing Rails

Rails depends on a Javascript runtime, install nodejs.

sudo dnf install epel-release
sudo dnf install nodejs

And now install Rails

gem install rails -v 5.1.5
rbenv rehash
rails -v

#Create your first Rails app

rails new myapp

# Move into the application directory
cd myapp

# Create the database
rake db:create

# Start the server
rails server

You can now visit http://localhost:3000 to view your new website.

Advertisements

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

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 🙂