Complete Development environment with Windows 10 and Linux — Part 2

Patrick_B
12 min readAug 16, 2018

--

This guide is for installing Linux Ubuntu 18.04 LTS in the Windows 10 environment on a PC, using Windows Subsystem for Linux.

March 2020 — Some nice changes from MSFT teams have turned obsolete some parts of this article. The new Powershell, WSL2 and some other features mean I need to revisit a good chunk of the subject. As I am working from home, like a lot of us I guess, it is on my To-Do list. So it’s Coming Soon (TM).

Stay at home and stay safe!

The base of this project came from a personal lack of comfort with the dominant coding machine, the one sporting a bitten common fruit. I personally don’t own any interest, share or sponsorship from any of the corporations mentioned in this article. This article is the second of two intending to install a viable, useful and professional development environment on a PC desktop or laptop. The first one can be found HERE. Some of the following info will refer to it, and avoid duplication.

The main components are:

  • Ubuntu 18.04LTS
  • Chrome
  • Git
  • Visual Studio Code
  • EsLint
  • Prettier
  • Node JS
  • NVM, NPM
  • Nodemon, Testem
  • PostgreSQL
  • DBeaver
  • Postman

IMPORTANT DISCLAIMER

Please note that some of the modifications could potentially brick your machine or necessitate a new install of Windows if done without precautions. Proceed at your own risk. The information in this post is true and complete to the best of my knowledge. All recommendations are made without any guarantee, implied or express, on the part of the author. The author disclaim any liability in connection with the use of this information.

OTHER IMPORTANT FACT

Some of the tools are implemented through the WSL/Ubuntu console, also known as Bash. DO NOT TRY TO IMPLEMENT LINUX/UBUNTU TOOLS THROUGH OTHER MEANS. Really, really bad things will happen. In short, before ANY installation or call to a resource, like installing a Node package or dependency, CHECK THOROUGHLY this happens in Bash, not in CMD prompt terminal, not in the PowerShell terminal, or anywhere else. Each time, the installation environment is detailed. Respect this.

Why Ubuntu? Why Windows? Why?…

Linux is more or less just the OS Kernel. Different orgs or companies use this kernel to put together a full OS. Microsoft has collabored with Canonical, owner of Ubuntu, to get that particular OS to function on Windows. The first article can be accessed for a bit more background on that. It is an on-going venture and more exciting stuff will come in the near future.

Now a bit more about that choice as a personal Dev’ box. As said previously, Macs are fine machines. I have the chance to own a Surface Book 2 and I prefer working on it for its comfort, its OS and its touch functions. It brings another dimension to delopment work, absent from the Apple eco-system so far. For instance, it can take an instant screenshot and use it as a background for writing on it. This is just awesome, basically offering our own whiteboard to scribble on with the base code or definition visible at the same time. It offers a large tablet where I can examine or handle a database, or jost a few notes for later work on my app. It makes mock-ups very easy to figure out. It is as well a great tool for presentations or code reviews. Those points are just a few among many others and one can see it differently. Tastes and colors…

Windows Sub-System for Linux

Microsoft WSL Developer Blog

In short: WSL.

It allows the installation and use of Ubuntu (18.04 in this case) within Win10. It is a Console App, not a virtual machine, not the Console per se. It can be represented like this:

It makes it possible to run and operate a complete Dev’ box, using Visual Studio Code, NodeJS and Github Desktop, ESlint (not global) and Testem , while keeping access to Win10 ressources. It may encounter some difficulties running global packages. PostgreSQL can run in the WSL “bubble” with some constraints.

It is a nice environnement, and it is rather easy to set up. Main caveat is it is somewhat slower than a native Linux environment. Some global installations will not work (as of the time of writing), though a lot of libraries and resources are best installed and used on a per-project basis.

Another consideration to be made is that WSL is still happening. It is not complete, it has still some flaws and bugs. It works for 95% of Dev’s needs and should see a lot more coming in the near future, as Microsoft seems to take into a account the coding crowd.

Windows requirements

To operate Windows Sub-system for Linux, the machine must run a Windows 10 version different from the Home version, so no 32-bit Windows. A latest build is also better. It is advised to run Fall Creator or later (Build 16215 and above).

First steps

Before any action, prepare a Windows 10 system image with the 32GB USB drive.

Backup your files and documents, so you have them in case something goes wrong. Use some DVDs or other USB drives.

What you need:

1 USB drive 32GB,

DVDs or some more USB drives.

Initializing WSL

First, enable the Developer mode in the settings:

Settings => Update and Security => For Developers => Click Developer mode ON.

Second, enable WSL through a Powershell command (official MSFT Docs)

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

or through Windows features (2nd tutorial).

After a restart, install the chosen version of Ubuntu, preferably the latest LTS. Microsoft Store provides different versions for free, as well as different distributions. Other distros may require different options and / or utility software. Some may not support all the features required by this environment. Just select and click `install`.

Restart again the computer.

Pin the Ubuntu client to the Start menu. Other quick links will get there in time, it is a handy place to gather all the Dev tiles (see screenshot at the end).

Bionic Beaver is alive!

At that point, you are pretty much done. Congratulations!

Ubuntu (or the chosen distro) is active in the Windows eco-system. One thing needs to be very clear. This is Ubuntu, this is Linux (actually the Linux binaries), BUT this is not a Linux kernel. It cannot be updated as seen in a dual boot config. The distro can be updated at this time through installing a new version of it.

If using a Surface device, no need to install a custom kernel, all the touch stuff and peripherics are working at peek efficiency. Important to say is that all this is still Win10, with Win10 drivers and processes, and so on.

Now comes the Dev environment set-up. This is in part the beauty of it, as a lot of tools implemented in Win10 can interact with Ubuntu via WSL and ports. This is illustrated in the next sections, as we take shamelessly advantage of it (cue in evil chuckles and pinky near mouth!)

WSL Linux for Fullstack Academy

There are some differences between the Toolbox from FSA and the implementation with WSL.

One important note: some software need to be installed in Windows, some in the Ubuntu console. DO NOT TRY to install Linux stuff through the PowerShell or Command Prompt terminal. Some really nasty effects will happen, with the potential of breaking down Win10. It bears being repeated.

Git (version manager, hosted on GitHub) should be the first item on the list. And it is best installed on both sides, meaning in Win10 AND in Ubuntu.

Open the brand new Ubuntu terminal and type:

User@Linux~$ sudo apt updateUser@Linux~$ sudo apt upgradeUser@Linux~$ sudo apt install git

After that, download and install Git in Windows, not the Ubuntu terminal. This will allow Git to run on both sides.

From experience, it is best to start with NVM and NodeJS, as presented in the first post. The same considerations apply.

Important : Git, Curl, NVM and NodeJS are installed IN the Ubuntu terminal.

Text Editor and linter

This is done on the Win10 side, not in the WSL-Ubuntu client.

Get to the download with the link, fetch the 64-bit version and install. Pin that tile to the Start Menu.In the same way, install GitHub Desktop. It may not be necessary, but it is quite helpful when things get a bit hairy in Git.

ESLint and Prettier will be installed from the Ubuntu terminal as will be the config files. See Part 1 for the specifics. ESlint and Prettier can be installed, and will work globally. But it is important to install the dependencies and peer dependencies globally. The config.file for ESLint will work the same and needs to be created. In short ESLint will look for a config file in the project directory and bubble up to Home/Root if not found before.

The same handling of Node Path for ESLint applies, as described in the first part.

There is one thing to add to the User Settings in VSC which will convert the VSC terminal into a WSL terminal. Add the following snippet to the new Settings:

“terminal.integrated.shell.windows”: “C:\\WINDOWS\\System32\\wsl.exe”

Good to know: VSC is based on Electron 2.0.12, meaning our machine needs to be connected to the internet to be able to open VSC. Yup, not great when there is no WiFi or RJ45 available. It is the subject of many issues on the VSC GitHub repo. AFAIK, it should be corrected in early 2019 by upgrading to Electron 3.0. More later!

Hitting the limits in WSL

WSL, as good as it is, will not play nice with GUI tools, so no GNOME or Linux Unity.

It is also not too good at global installations. One work-around is to integrate them in one’s boilerplate package.json. Finally, the Ubuntu 18.04 provided works around a binary set from Linux kernel v. 4.04, not the most recent version of it. It is best left alone, no need to update.

Installing PostgreSQL

This is a necessary item with 2 options, both with trade-offs. One is to install PostgreSQL for Win10, but then the PostgreSQL server will start with Win10, every time, and stay on all the time. It may be something not needed nor wanted.

The other way is to install PostgreSQL on the WSL side so it is sandboxed sort of, which is what is described further down. On the flip side, the server needs to be restarted each time a WSL session is started. In some instances, the database needs to be created before the app scripts sync the app DB part to the database. Be cautious and take it slow, this part is pretty involved and can go sideways easily.

First, open a WSL/Ubuntu window and update/upgrade the Ubuntu machine

User@Linux~$ sudo apt updateUser@Linux~$ sudo apt upgrade

The installation of Postgres is similar to the Part 1.

User@Linux~$ sudo apt install postgresql postgresql-contribUser@Linux~$ sudo -u postgres createuser --superuser <$YOUR_USERNAME>User@Linux~$ createdb <$YOUR_USERNAME>

Then edit pg_hba.conf the same way, the version number is 10 as of August 2018.

User@Linux~$ sudo nano /etc/postgresql/VERSION_NUMBER_HERE/main/pg_hba.conf

Replace the md5 values by trust, moving with the arrows and typing in the same exact spot. The file should look like this:

Confirm with CTRL + O, then ENTER, and exit with CTRL + X. Go back to home with cd ~.

Restart postgreSQL. It is the same command line for each time it is restarted. Or write a quick script to be executed when WSL is loaded.

Starting and stopping PostgreSQL service

The main trade-off from installing PostgreSQL in WSL-Ubuntu and not in Win10 is to restart the PostgreSQL server each time the Ubuntu client is opened. Do it with :

User@Linux~$ sudo service postgresql start

The other part is that the same server needs to be shut off when leaving. The server will continue taxing the memory and the CPU because of the Unix socket it uses. This can cause the machine to heat up nicely. On thin machines like the Surface devices, it can be an issue. Use the following command:

User@Linux~$ sudo service postgresql stop

A few words on coding with a WSL environment

It is a very comfortable coding environment. After a few weeks of 9 to 12 hrs a day typing/debugging/going through code, my personal assessment is really positive. My SurfaceBook 2 is a great machine for the present purpose.

There are still a few points which could make a difference. First of all is the execution speed. As most of the processes are going through the Console API, the speed is obviously diminished. All the NodeJS stuff happening with a server is taking more time to execute. It can be seen with ESLint, a testing library, Webpack building, even PostgreSQL.

Another point is that heat emission is increased, as the CPU and the RAM are doing most of the heavy lifting. It is more a concern with thin laptops or machines where the ventilation is limited. Fortunately, there are many tools available in Win10 to monitor that. Desktops are very probably less prone to it.

Finally, coming from the 2 points above, some servers in the console do not close completely some times. When the Ubuntu or the WSL terminal is closed, some processes on server, notably NodeJS or PostgreSQL can stay active and run in the background, hogging resources. Due to producing an output not going somewhere, it can produce a lot of heat. I had a couple of occurrences where the SB2 went up to 95 degrees Celsius. It is then important to always terminate the PostgreSQL server, and/or kill the terminal in VSC when done. This needs to happen even if the machine is put to sleep. Hibernate should stop those processes.

Installing some Tools

From previously, Homebrew, or more exactly its little brother for Linux (Linuxbrew), will not work well in WSL, so skip it.

ZSH and Oh-My-Zsh will work, if preferred. A terminal manager like ConEmu can also be used, it’s just not completely necessary. It can run some GUI apps in WSL though. There are some possibilities but the cost in time may be a bit too much to really be interesting.

1. Postman, a really great tool for back-end development. Here, the Win10 version will be installed, from the Win10 side, NOT the WSL-Ubuntu side. It works off the port served by the app, so it needs to simply plug in the same port.

2. DBeaver: installed on the Win10 side, as WSL does not support GUI. Setting up the connection in DBeaver can be a tad tricky. First, the JDBC driver needs to be installed, via the tab Driver.The connection parameters are mainly the user previously created, and the relevant password, if one has been defined. Check in the DB window if the <your_user> database can be accessed, even if it is presently empty.

3. Nodemon and Testem: they can be globally installed.

4. Psql cheat sheet: The kind of handy link to have somewhere, just in case.

It is more comfortable to get all these grouped in the Start Menu, even more so with a touch screen device. It should look something like this:

Which browser?

Firefox is a good option, but Chrome or its open source twin Chromium are probably better for development. Just the debugger, if it’s the only aspect considered, is so worth the install. On the other hand, Firefox Inspector is quite good too. Your choice, or load them both.

It may be a good idea to add Chrome to the PATH in WSL. This allows chrome.exe to be invoked from the WSL prompt. It can also be opened from Win10, and used the same way as well.

Testing

All those modifications have been tested on:

Custom-built desktop PC i-5 4690K overclocked, 16GB RAM, 2TB storage (SSD/2HD), GTX 1070 NVidia 8GB,

Surface Pro tablet (2017) i-7, 8GB RAM, 256GB SSD,

Surface Book 2 i-7, 16GB RAM, 1TB SSD, GTX 1060 NVidia 8GB.

All are running Windows 10 — April 2018.

Microsoft, Windows, Windows 10 are trademarks of Microsoft Corp. MacBook Pro is a trademark of Apple Inc. Ubuntu is a trademark of Canonical Inc. UK.

Thanks to Dakota Blair and the whole team at Fullstack Academy for their precious help.

--

--

Patrick_B

Coder, pro chef, tech head. Presently front-end developer at the Literary Assistance Center(NYC).