In this post, we explore how to install and set up Ubuntu on Windows 10 using Windows Subsystem for Linux (WSL). We also cover installing pip and venv for Python 3, setting up Git, creating an SSH key for connecting to GitHub, and installing Docker.

About Windows Subsystem for Linux

From the WSL Wikipedia entry, “Windows Subsystem for Linux (WSL) is a compatibility layer for running Linux binary executables (in ELF format) natively on Windows 10 and Windows Server 2019.”

In contrast with PuTTY or GitBash, which provides a terminal to Windows users for running Linux commands, WSL enables you to run your favorite Linux distros alongside Windows applications. In consequence, you can install and run native Linux binaries using your selected distro’s software management system, such as apt-get in Ubuntu.

WSL is fast and uses relatively few system resources.

System Requirements

To use WSL, you need Windows 10 – 64bit – version 1607 or above. WSL also runs on Windows Server 2019.

Enable WSL

Enabling WSL is simple and requires a single PowerShell command. Open PowerShell as Administrator and run:

Restart the computer.

Install Ubuntu 18.04 on Windows

After the restart, open the Microsoft Store and search for Ubuntu 18.04 LTS. Click on Install. Once installed, launch it. Ubuntu is now running on Windows. You can proceed with setting up some important development tools.

Set up Ubuntu on Windows

The first thing you have to do after launching Ubuntu on Windows for the first time is to create a new UNIX user, so enter after the prompts a username and a password.

You can now update the package list index and upgrade Ubuntu:

Set up Python and development tools

Ubuntu 18.04 LTS comes with Python 2.7.15 and Python 3.6.4 installed. You will most likely be using Python 3.7 or later for your development work. However, you should not to change the default versions of Python and, instead, you should rely on setting up a virtual environment with the correct Python interpreter directly in PyCharm or in your prefered IDE.

You do have to install pip and venv for Python 3, so run the following commands:

Set up Git

Git comes installed with Ubuntu 18.04. To verify which version you have, run:

You should configure a Git global user name and email and set up an SSH key to connect to GitHub. Setting this up now saves a lot of time when committing and pushing to GitHub.

First, configure the Git user and turn off auto line endings by running the following commands (replace where applicable with your own information):

Now, create an SSH key for connecting to GitHub:

Press enter when prompted to accept the defaults. Your key is saved to ~/.ssh/id_rsa. The prompts should look similar to this:

Next, add a config file for SSH:

And insert (by pressing i and typing) the following lines:

Save the changes (by pressing Esc, and then :wq).

Next, run the following commands to add your SSH key to ssh-agent:

Finally, your are ready to add the SSH key to your GitHub account. To display the public SSH key run:

Copy it with Ctrl + C.

Go to GitHub and under Setting / SSH and GPG keys, add a new SSH key, give it a title, and paste the key.

Set up Docker

For Windows 10 Pro Users:

If you are using Windows 10 Pro, make sure you have Docker Desktop installed and running on Windows. If needed, follow the instructions at Docker.

Access the Docker settings by clicking on the Docker icon at the system tray. In the General tab, check the Expose daemon on tcp://localhost:2375 without TLS box.

On Ubuntu, you need to create an environment variable for the DOCKER_HOST that points to the docker daemon. You should add this variable to the .bashrc file so it is always available on Ubuntu.

Open ~/.bashrc:

And add the following lines at the end of the file:

For Windows 10 Home Users:

Docker Desktop does not run on Windows 10 Home, so you have to install Docker Toolbox. If needed, follow the instructions at Docker.

With Docker Toolbox, you can’t expose the Docker daemon without TLS by just unchecking a box, as you would do with Docker Desktop. Instead, you have to add environment variables for the docker host address and for the TLS certificate location.

In the Docker Quickstart Terminal run:

You should get something similar to this:

Add these variables to the .bashrc file so they are always available on Ubuntu.

Open ~/.bashrc:

And add the following lines at the end of the file:

For all Windows users:

Once WSL is configured to connect to Docker Desktop or Docker Toolbox, the rest of the instructions are the same for all Windows users.

Update the apt package list index and install the following packages to allow Ubuntu to access the Docker repos over HTTPS:

Add Docker’s GPG key, install the Docker repository, and update the package list:

You can now install docker-ce and docker-compose and add your user to the docker group:

Finally, to ensure that docker-compose finds that right paths for the Windows file system, you need to modify the wsl.conf file.

Open /etc/wsl.conf :

And insert the following lines:

Note for Windows 10 Home users:

If you are using Windows 10 Home and added an environment variable for DOCKER_CERT_PATH to the .bashrc file, you must fix the path now to account for the change in the automount.

Open ~/.bashrc:

And replace the following line:

With:

Set up a version control directory

Your Git repositories should be in your Windows file system. In my case, they are at c:Usersjfeliversion-control. To save time during development, you want Ubuntu on Windows to open directly on that directory upon start. Luckily, this is easy to achieve by modifying the ~/.profile file.

Open ~/.profile:

And add the following lines at the end of the file:

Conclusion

In this post, you installed Ubuntu on Windows 10 and also set up pip and venv for Python 3, Git, Docker, and create an SSH key for connecting to GitHub. You now have a basic setup that will increase your productivity as a developer.

References

You may also like:

Show CommentsClose Comments

Questions? Comments? Leave a reply to start a conversation...

Discover more from Wander In Dev

Subscribe now to keep reading and get access to the full archive.

Continue reading