Development Environment on Windows with WSL
- #Linux
Objective
The development environment is a hard part of the work as software engineering, so the main goal of this article is to show an alternative for developer who uses windows as main OS to turn that pain part more soft.
Methodology
This is a solution focus approach, without verbose explanation about terms and motivations. This because the time is so important and most developers doesn't care about it when learn articles like this.
So, let's start.
Hands-on
First recommendation: use the Windows Terminal! This article uses it.
For better experience and gain time to access the environments, pin the Windows Terminal to taskbar.
Access the Windows terminal and use it to run all the following commands.
Environment Configuration Steps
1. Access your desktop
Using the Windows Terminal:
cd ~/desktop
2. Check the available distributions
The WSL offers many commands to manipulate its distributions by using the wsl command.
To list all available Linux distributions that can be used in wsl, use:
wsl --list --online
3. Install the desired distribution
To install a desired distribution, follow this command syntax :
wsl --install <Distribution Name>
For this article purpose, the Kali Linux will be uses as example.
wsl --install kali-linux
The credentials to use this new environment will be asked, so, inform the desired username and password there.
4. Export to a tar file
Export the created environment to a tar file.
wsl --export kali-linux kali.tar
This process is necessary to change the name of the environment and to specify the virtual drive location.
5. Create a Directory to store the Drive
You can store the virtual WSL driver anywhere. For this article, it will be stored in c:/wsl
mkdir c:\wsl
6. Environment Creation (the Import process)
This is the process of real environment creation.
To do that, import the distribution (exported as tar file) to a specific place and with a specific name.
This name is important, because it must describe the real intention of the environment.
In this article, the name will be "back", because it is designed for a back-end purpose. If you work with many projects and want to maintain the environment without any changes, the suggestion is to set the project name with the purpose, like "project_name_backend", "project_name_frontend"...
Following this article example, the command is:
wsl --import back c:\wsl kali.tar
7. Check if it works
To verify if the environment was created, list all environments with this command:
wsl --list
If the name of your environment doesn't appear in the list, repeat the process, check if an error occurs and solve it.
8. Access the environment first time
To access, use the wsl command with -d parameter and the name of your environment.
For this article example:
wsl -d back
You can type exit to return to windows.
Now you can have your specific project and layer environment specified.
9. Relaunch the Windows Terminal
When you relaunch the windows terminal, it recognizes this new environment and shows you the option to start it from taskbar just by pressing the right mouse button and selecting the desired environment.
10. Beautify
You can set an icon and a specific background to this environment. It is useful to distinguish it from others environments.
11. Configure the host name
Access your environment:
wsl -d back
Edit the wsl.conf file:
sudo nano /etc/wsl.conf
Set the desired hostname there. For this article purpose, the "mybackend" hostname is used:
The "generateHosts = false" is important, don't change it to true and don't remove it.
Just for copy-paste purpose, this is the text:
[network]
hostname = mybackend
generateHosts = false
Save the changes (CTRL+O) and exit the editor (CTRL+X).
Now, edit the Linux hosts configuration:
sudo nano /etc/hosts
Change only this line:
Save the changes (CTRL+O) and exit the editor (CTRL+X).
Exit the environment - returning to the windows - and terminate the environment execution:
wsl --terminate back
Now, when access it again, the host will be the informed.
wsl -d back
12. Change the default user (optional)
If you want to change the default user, you can set it in the wsl.conf file - after creating the user, obviously:
[user]
default=myusername
After changing the wsl.conf, the environment must be terminated and relaunched to take effect.
13. Enjoy it
Now you can install all tools you need for your project environment necessities.
No more projects lib conflicts or unnecessary tools.
14. No more need it
If your environment became an unnecessary workspace, just unregister it from WSL.
wsl --unregister back
More about it
There are more content like it, if you want:
That's all, folks
That is it.
If you have any trouble in any step, just comment here and I'll try to help and change the article content to make it more clear.