Skip to content

Instantly share code, notes, and snippets.

@jasonpilz
Forked from selfup/vagrant_for_turing.md
Created January 22, 2016 22:21
Show Gist options
  • Save jasonpilz/44da5d8d4b316ca6d408 to your computer and use it in GitHub Desktop.
Save jasonpilz/44da5d8d4b316ca6d408 to your computer and use it in GitHub Desktop.

- Mission

The purpose of this tutorial is to mimic setting up a DigitalOcean/AWS EC2/Linode server. The main advantages of having a virtual machine is that you can learn without worry of breaking things.

The first lesson will be all about getting familiar with a headless machine and getting a language we all know and love (ruby). Then we can mess around and try things out purely in the terminal.

The only three good options for a text editor are: emacs, vi, and vim. We will be using vim but vi itself is great and comes by default on Ubuntu 12.04.

Now you can practice getting used to ssh'ing into headless machines, using terminal based text editors, and using a terminal based window/session manager (tmux). The reason we have to use vim and tmux is that there is no X environment in a headless machine (the GUI, graphics, pretty things, etc..). The main reason for this is to save space on precious costly SSD data.

Getting comfortbale with DevOps before being on the job will benefit you immensely. Moving away from Heroku as time goes on will give you more freedom and better tools. I also love intoducing people to GNU/Linux so this is a great start at getting multiple things done while empowering you with rarely taught knowledge.

- Download Virtual Box

  • Here
  • Now click the amd64 link: VirtualBox 5.0.6 for OS X hosts
  • Or just click this automatic download link: Here
  • Install VB

- Download Vagrant

  • Go to this page
  • Or click this automatic download link for Mac OSX 64bit: link
  • Install Vagrant

- Detailed instructions will be taught during my session!

Quick resource for setting up vagrant

Here is the official getting started documentation for Vagrant: link

Go to a non root directory or mkdir Vagrant at root
cd into Vagrant
vagrant init hashicorp/precise32
vagrant up

Things will start happening during the init and vagrant up phase. Be patient, it won't take long!

Now it's time to ssh into the VM

vagrant ssh

You are in a Virtual Machine! Whoaaa

- Software we must get to be ready

sudo apt-get update
sudo apt-get install htop 
sudo apt-get install tmux 
sudo apt-get install vim
sudo apt-get install git

- Ruby for Ubuntu

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

Now we go get rbenv (ruby version manager) and install ruby

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

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

. .bashrc
. .bash_profile

git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash

rbenv install 2.2.3
rbenv global 2.2.3
ruby -v

- Node for Ubuntu

How to get Node for Ubuntu

Here we go:

dpkg --get-selections | grep node

sudo apt-get purge nodejs npm

curl -sL https://deb.nodesource.com/setup | sudo bash -

sudo apt-get install -y nodejs

node -v

npm -v

Now to force update to the freshest version of everything:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

- Ruby and Node? Get Rails for Ubuntu!

gem install rails -v 4.2.4 --no-rdoc --no-ri

Now you need to "rehash" rbenv

rbenv rehash

Should be good to go. To be sure just:

ruby -v
rails -v
node -v
npm -v

- Install pry and ag to verify everything works as you would expect it to

gem install pry
gem install ag

- Today we will set up a Digital Ocean Droplet. Your Public SSH keys are connected to your own droplets so we now just need to log in via SSH:

ssh root@your_servers_ip
apt-get update && aptitude dist-upgrade -y && apt-get autoremove -y

If this is your first time setting a droplet up, follow this gist from the top!

Once everyone has rails, pry, and ag: we will do:

rails new newapp
rails s

Now we can go to the servers IP/3000

And you should see the normal rails message!

- Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment