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.
- Here
- Now click the amd64 link: VirtualBox 5.0.6 for OS X hosts
- Or just click this automatic download link: Here
- Install VB
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
sudo apt-get update
sudo apt-get install htop
sudo apt-get install tmux
sudo apt-get install vim
sudo apt-get install git
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
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
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
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 OR if you want a much faster process go to this gist!
For security please do the following if you have SSH access
vim /etc/ssh/sshd_config
Hit i
to enter INSERT mode
Find the PermitRootLogin
and change it to
PermitRootLogin without-password
esc
:wq
Now hit Enter
Now to ensure that your server cannot be brute forced, do the following:
service ssh restart
Once you have 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!