In my previous tutorial we went over how to install Ruby on Rails using the Windows subsystem for Linux. A fair amount has changed since I created that video so I thought I would share some updates.

Click here to view the previous tutorial.

First of all, you can now install Ubuntu directly from the Windows store. I currently have Ubuntu 18.04 (Bionic Beaver) installed on my computer. This means you no longer need developer mode, and you can uninstall Ubuntu the same way you do with other programs - aka add or remove programs.

If you installed Ubuntu through the Windows store, or if you are on a newer Windows build, the file paths are now hidden by default. This is to prevent you from using Windows tools to edit these files. However, if you do want to see these files, open up your quick access toolbar and paste this in %userprofile%\AppData\Local\Packages

This should lead you to the right folder: mine looks like this:

C:\Users\Brian Gilbank\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home\bg

I simply created a shortcut to this folder on my desktop, so I can easily add folders and files to my text editor.

PostgreSQL Update

After completing the October 2018 update for Windows (build 17763.1), I was finally able to install PostgreSQL natively, instead of on the Windows side of my machine.

This is how i did it

sudo apt-get update
sudo apt install postgresql postgresql-contrib

Start the server and install pg dependencies

When running PostgreSQL on Ubuntu in the Windows Subsystem for Linux, you may have to manually start the database server before you can connect. We will also create a new Postgres user during this step.

sudo /etc/init.d/postgresql start # should start the database server

# Now lets create a new user 
sudo -i -u postgres
createuser --interactive #create a new user.
Enter the name of the role to add: # Pick the same name you used for your Ubuntu username
Shall the new role be a superuser? (y/n) # Select y.

# Install pg gem dependencies
sudo apt-get install libpq-dev

While this setup worked for me, its still a little buggy and you may run into errors. But if this worked you can now install Ruby and Rails.

Installing Ruby on Rails

Code provided by Go Rails, a great resource for learning Ruby on Rails.

Install Ruby dependencies

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 software-properties-common libffi-dev

Install rbenv

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

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

rbenv install 2.5.1
rbenv global 2.5.1
ruby -v

Install Bundler

gem install bundler
rbenv rehash

Installing Git for version control

git config --global color.ui true
git config --global "YOUR NAME"
git config --global ""
ssh-keygen -t rsa -b 4096 -C ""

Adding your SSH key to Github

cat ~/.ssh/

Copy and paste the output into your Github account. Check that it worked by running ssh -T in your terminal.

Install Rails

# Install Node.js
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

# Install Rails 
gem install rails -v 5.2.0
rbenv rehash
rails -v
# Rails 5.2.0

That's it, lets create our first app

rails new appname -d postgresql
cd appname
rails s
You successfully installed Rails

Finally, let's fix the ugly Bash terminal

You may have noticed that the Bash terminal colours are almost unreadable, especially with that weird blue colour. However, we can fix it easily thanks to this post by Iraklis Mathiopoulos on Medium.

vim ~/.bashrc
# This will open your ~/.bashrc file
# Now paste in this code:

export LS_COLORS
:wq! #save and close the file

You can also change your prompt colour and its format with this:

vim ~/.bashrc
PS1='\e[37;1m\u@\e[35m\W\e[0m\$ '
:wq! #save and close the file

Finally, set your vim background to dark

# In the terminal run:  
echo "set background=dark" >> .vimrc

And Viola

Terminal Output Exmaple