History

From my previous posts, you might know that I volunteer as an Engineer on the site https://www.ishtar-collective.net. This site is a Rails app and running Rails on Windows has been possible for a long time, but there’s one little issue with Ishtar that makes running it in a Windows environment an issue - the Ruby Version Manager of choice for the project is https://github.com/rbenv/rbenv. Rbenv does not support Windows at all. Since I’m the only member of the Engineering Team that uses Windows as their daily driver, it’s up to me to make this work. I’m a firm believer that it’s not fair for me, as a member of the team, to push my opinions/changes on other team members unless those changes have value for everyone. Nor do I think it’s fair that the projects workflow be changed, just because of me. This topic can be expanded on much further, but it’s not relevant to this post.

Vagrant

Over the last year and half, I’ve used a personal Vagrant environment that has worked very well for me. Every now and then though, I would boot up the environment and everything would either be lost or for whatever reason, could not boot - which meant that I had to rebuild everything from scratch. End result was still the same. Everything was lost and had to be rebuilt. Also, as the project grew, so too did the needs of the environment and in turn, on my system. This began to put a pretty large strain on my aging dev laptop. To the point that to boot into a branch of the project could take upwards of 5 mins. Just to bring the site up in a browser took well over a minute and page changes were around 2-3 seconds. From a web development stand point - totally unacceptable!

Docker

Yes, I tried Docker and have a working branch of the project on Docker. Well, working is a slight over statement. There ended up being some issues with Memcached not working properly, and branches not working as expected. I’m sure these are all because of my lack of experience with the product and not the product itself. I still use Docker, locally, for many other projects and it seems to work just fine. At the end of the day, the other team members just ran into too many issues to justify its own value. Granted, if we do keep our long term plan of moving to GCP and Kubernetes, we will need to sort these issues out. That’s a battle for another day though.

Windows Subsystem for Linux

About a year ago, I had to replace the HDD in my dev laptop and I took advantage of the low SSD prices to exchange my overworked 1TB HDD for a 250GB SSD. The performance improvements are just astounding! But, I reinstalled Windows 10. I could’ve easily averted a lot of the last years headaches by installing Ubuntu instead. And that’s were WSL comes in. Now that all my other options have failed me, one way or another, WSL will allow me to run an isolated instance of Ubuntu from which I can freely install all the stuff I want. So! Let’s get started.

Install WSL

I will refer you to MS’s https://docs.microsoft.com/en-us/windows/wsl/install-win10 page. This is for more complete and up-to-date instructions.

Update Your Installation

Once inside your WSL installation, you are going to want to run - sudo apt update && sudo apt dist-upgrade && sudo apt-get autoremove && sudo apt-get clean

This will update all the default packages that came installed in Ubuntu 18.01. From here, we need to install only a few things. Ruby, RBENV and PostgreSQL being the most important. ElasticSearch is totally optional for a standard environment.

Next, let’s update the environment - 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 libreadline-dev libpq5 libpq-dev postgresql postgresql-contrib postgresql-client

Postgres

To make Postgres start each time you boot up your WSL envrionment, simply enter the following on the cmd line: sudo update-rc.d postgresql enable Postgres data will be stored in /var/lib/postgresql/10/main

Install Rbenv

Well, since Rails is a Ruby based framework, we might want to install it next. To do that, we need to install RBENV which will act as our Ruby Version Manager.

To do this, we pass the following line of code to the terminal - curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash

After which, we need to add Rbenv to our path. To do that, we then need to enter the following to do just that:

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

Clone the Ishtar Repo

Now we just need to clone our repo, using HTTPS. Change into the /mnt/c directory of WSL (this is your “c:” drive in Windows by the way. If you want to put your projects deeper, you can). I will not enter the path to the Ishtar repo, since it’s a private repo.

Install the Projects Version of Ruby

rbenv install. That’s it! Well, not really. :(

Setup VSCode to Use Bash in the Terminal

By default, VSCode wants you to use PowerShell. In our case, we need to use Bash by default. To make this change, go to File->Preferences->Settings (or type CTRL-) and search for terminal. Scroll down until you see an entry like so -

Open the JSON settings file and change the default terminal to point to your bash.exe. For me, it was "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\bash.exe",

Now you can CD into the new isthar-collective directory and type code . (if your using Visual Studio Code) and VSCode will open your project.

Setup ElasticSearch

To setup ElasticSearch we need to add the ElasticSearch PGP Key since they sign all their packages. Do this by entering the following - wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -.

Next, we save the ElasticSearch repo to a list - echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

We can now install the latest version of ElasticSearch - sudo apt-get update && sudo apt-get install elasticsearch

And to make sure that ES boots at launch and is ready for our site to load: sudo /bin/systemctl enable elasticsearch.service

You should see output similar to the following:

unisys12@DESKTOP-3LSQHQ2:~$ sudo /bin/systemctl enable elasticsearch.service
Synchronizing state of elasticsearch.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable elasticsearch
Created symlink /etc/systemd/system/multi-user.target.wants/elasticsearch.service → /usr/lib/systemd/system/elasticsearch.service.

But wait! There’s more!

Setup Java

ElasticSearch requires that Java be installed on your system, so… let’s tackle that now. Thankfully, it’s pretty simple - sudo apt install default-jre Not much else to do here but add Java to your path.

Use the update-alternatives cmd to see where Java is installed. sudo update-alternatives --config java

Edit the file etc/environment to include the following: sudo vim /etc/environment

Add the path to Java to a variable called JAVA_HOME: JAVA_HOME="/path/to/your/java"

Congratulations

Your done setting up your basic Rails environment within WSL or Ubuntu! But your still not ready to run Ishtar. There are quit a few more steps needed to get the homepage to load correctly in a browser. But! As for a fairly standard Rails environment to play around in, this might fair excited what most will need. Elasticsearch and Postgres are totally optional in this regard. We use Elasticsearch for search on the site and PostgreSQL as our database. Insert your database of choice -> here! Just subtract Elasticsearch if you have no need for it. You can always add it later!

Summary

Honestly, I’m very happy with the experience thus far. Since starting the documentation of this article, I have already submitted my first PR to Ishtar in almost a year. You have no idea how happy that makes me feel! I love this project and I am totally committed to it. If not, I would not have spent the last year working toward a viable environment for me to work in. And honestly, I was just about to reformat my SSD and install Ubuntu just so I could. This was a last ditch effort… and it worked!

Downsides

Well, at this point, I’ve not experienced any. Although I’ve not experienced a version update to Windows yet. I’ve heard that a full reset of your environment can happen during some updates. Since I’ve not experienced that, I cannot comment it.

Upsides

As for performance, this current WSL environment (Windows 10 Pro 1809) performs far better than my previous Vagrant environment. I will admit though that this environment is running on a SSD, whereas my previous Vagrant environment was on a HDD. With that, it’s not fair for me to make any comparisons between the two. I did try to get my most recent Vagrant file to work on my current SSD, but I encountered several crashes and unexpected reinstalls for no real reason. This probably has nothing to do with the SSD and more to do with installing a really old version of Ubuntu (16.04 LTS) with a host of more modern software. And now that everything is documented, if everything does reset, I can just follow along with my own blog post to get back up and going.

Aside from the above rambling - I’m working on Ishtar again! How cool is that and what more could I ask for?


Unisys12

Hobbyist web developer and gamer