Ubuntu Server Setup Part 5 - Install Git, Ruby and Jekyll27 Aug 2018
- Part 1 - Logging In
- Part 2 - Securing Login
- Part 3 - Installing a Firewall
- Part 4 - Setup Nginx Web Server
- Part 6 - HTTPS With Let’s Encrypt
- Part 7 - Email Forwarding with Postfix
- Part 8 - Sending Email Through Gmail
This part will take care of installing everything necessary to allow the new server to host your personal blog (or other Jekyll site). As a prerequisite, you will also need some kind of web server installed (such as Nginx or Apache) to take care of serving your
HTML files over the web. Part 4 covers the steps for my favourite - Nginx.
As I store my blog as a public repo on GitHub,
Git first needs to be installed to allow the repo to be cloned and new changes to be pulled. Git is available in the Ubuntu repositories so can be installed simply via
sudo apt install git
You might also want to modify some Git config values. This is only really necessary if you plan on committing changes from your server (so that your commit is linked to your account). As I only tend to
pull changes, this isn’t strictly required.
sudo apt install git git config --global color.ui true git config --global user.name "me" git config --global user.email "email
Helpful Git Aliases
Here are a few useful Git aliases from my
.bashrc. You can also add aliases through Git directly via the alias command.
alias gs='git status' alias ga='git add' alias gaa='git add .' alias gp='git push' alias gpom='git push origin master' alias gpu='git pull' alias gcm='git commit -m' alias gcam='git commit -am' alias gl='git log' alias gd='git diff' alias gdc='git diff --cached' alias gb='git branch' alias gc='git checkout' alias gra='git remote add' alias grr='git remote rm' alias gcl='git clone' alias glo='git log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short'
More helpful aliases:
Ruby is also available in the Ubuntu repositories. You will also need
build-essential to allow you to compile
sudo apt install ruby ruby-dev build-essential
It’s a good idea to also tell Ruby where to install gems - in this case your home directory via the
GEM_HOME environment variable. Two lines are added to
.bashrc to ensure this change is kept for new shell sessions:
echo '# Install Ruby Gems to ~/gems' >> ~/.bashrc echo 'export GEM_HOME=$HOME/gems' >> ~/.bashrc echo 'export PATH=$HOME/gems/bin:$PATH' >> ~/.bashrc source ~/.bashrc
You should now be able to run
ruby -v to ensure everything is working.
Once Ruby is installed, the Jekyll gem can be installed via
gem install jekyll bundler
I also use some extra Jekyll plugins which can also be installed as gems:
gem install jekyll-paginate gem install jekyll-sitemap
As the path to the Ruby gems directory has been added to the
PATH (in the previous section), the
jekyll command should now be available:
jekyll -v jekyll build
Here is a simple bash script which pulls the latest changes from Git, builds the Jekyll site and copies the site to a directory as to be served by your web server (default location is
#!/bin/bash echo "Pulling latest from Git"; cd ~/blog/ && git pull origin master; echo "Building Jekyll Site"; jekyll build --source ~/blog/ --destination ~/blog/_site/; echo "Jekyll Site Built"; echo "Copying Site to /var/www/html/"; cp -rf ~/blog/_site/* /var/www/html/; echo "Site Copied Successfully";