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


cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
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.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 user.name "YOUR NAME"
git config --global user.email "YOUR@EMAIL.com"
ssh-keygen -t rsa -b 4096 -C "YOUR@EMAIL.com"


Adding your SSH key to Github


 cat ~/.ssh/id_rsa.pub

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

Install Rails


  # Install Node.js
  curl -sL https://deb.nodesource.com/setup_8.x | 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:
  
LS_COLORS='rs=0:di=1;35:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:';
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 example