Setup of Ubuntu environment using WSL

This page summarizes the procedures for setting up an environment running Ubuntu using Windows Subsystem for Linux on a Windows 11 environment.

Prerequisite

In this environment setting, the following machines were tested in the following environment.

Basically, as long as the environment runs WSL, the following procedures can be used to develop the environment.

Set up a WSL environment

First, several components must be installed in order to run WSL. This procedure can be proceeded by executing the following commands

sh
Image

Once the reboot is complete, the WSL can be used.

Installing Ubuntu

Select a Linux installation image from the Microsoft Store. In this case, we will install an Ubuntu application.

Image

When you start the program for the first time, you will need to set up a user name and password. Please follow the steps displayed on the screen to proceed with the setup.

Image

Update the package index of the Ubuntu system on which you have installed.

Image

You are now ready to install the various packages.

Installing Node.js

To set up an environment for developing applications such as Next.js and Astro, we will first install Node.js. In addition, we will install n so that we can easily switch between Node versions.

Installing node and npm

First, install node and npm, which are provided as Ubuntu packages.

sh

After the installation is complete, the respective versions are displayed as follows.

sh

First of all, node and npm now work.

n Installation

Then install the command n, which allows you to easily switch node versions.

sh

When the installation is complete, run the following command to check the version.

sh

This completes the installation of the n command. Use this command to install the lts version of node.

sh

The version 22.15.0 is installed at the time of execution.

Image

To reset the internal hash table of the shell to refer to the path of the node installed with n, execute the following command

sh

After execution, check the version of each command.

sh

We have confirmed that we recognize the new version.

Uninstall node

Now that node installed with n has been installed, remove the node and npm packages installed with the apt command that was used to install the first time.

sh

The environment for using node and npm is now ready.

Installing Visual Studio Code

Now node is running in the Ubuntu environment running on WSL. Next, install Visual Studio Code, which is installed in the Windows environment. This time, we installed Visual Studio Code from the Microsoft Store.

Image

Start Visual Studio Code after installation, open the Install Extension screen, enter the three letters WSL, and install the Microsoft WSL extension that comes up as a search result.

Image

This will allow Visual Studio Code to work with WSL.As soon as possible, open the Ubuntu command line screen and execute the following command.

sh

For the first time, perform the installation of the required components into the Ubuntu environment.

Image

When Visual Studio Code starts, you will see that it is connected to the Ubuntu environment. You will see WSL:Ubuntu in the lower left corner of the screen below, and you will also see that all files are from your Ubuntu home.

Image

Now that the above situation is in place, it is possible to develop in the Ubuntu environment using Visual Studio Code.