Dev Notes

Software Development Resources by David Egan.

Install Ruby & Ruby on Rails in Ubuntu Xenial


Ruby
David Egan

This guide involves:

  • Setting up Ruby using rbenv
  • Installing Node
  • Installing Rails

Install Ruby Dependencies

Packages required to build 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 libcurl4-openssl-dev python-software-properties libffi-dev

Install rbenv & ruby-build

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc

# Add command completion scripts into path
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

rbenv install 2.3.1
rbenv global 2.3.1
ruby -v

Install Bundler

gem install bundler
rbenv rehash

Set Up Git Globally

If you haven’t already done it…

git config --global color.ui true
git config --global user.name "David Egan"
git config --global user.email "you@example.com"
ssh-keygen -t rsa -b 4096 -C "you@example.com on xenial-ghost"
cat ~/.ssh/id_rsa.pub

Copy and paste the contents of the public key to Github/BitBucket.

Check the ssh connection:

ssh -T git@github.com

Set Up Node

Install Node using NVM (Node Version Manager)

See: http://linoxide.com/ubuntu-how-to/installing-nodejs-ubuntu-16-04/

sudo apt-get update
sudo apt-get install build-essential libssl-dev curl
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash
source ~/.profile
nvm ls-remote
nvm install v6.2.2
node -v

Build a quick hello world node app to check:

nano hello.js

# Enter:
a="Nice";
b="One!"
c=2;
d=2;
e=c+d;
console.log(c +' plus '+d+' equals:' +e);
console.log('Hello World! '+a+' '+b);

Run node hello.js in the terminal to output:

2 plus 2 equals:4
Hello World! Nice One!

Install Rails

gem install rails -v 4.2.6
rbenv rehash
rails -v

Build a New Rails App using MySQL(MariaDB)

Assuming that a MySQL server is already installed on the system, prepare Rails for MySQL:

# Requirement to compile the mysql2 gem
sudo apt-get install libmysqlclient-dev

# Gem used by Rails to connect to MySQL
gem install mysql2

Set up new Rails app:

rails new railsapp -d mysql
cd railsapp
rake db:create
rails server

References


comments powered by Disqus