- Install WSL
- Run “Windows Powershell” as administrator
- Execute the below command to install, then setup user/password
wsl --install -d OracleLinux_9_1
NOTE:
If you face the “Error 0x80370102 The Virtual machine could not be started because a required feature is not installed”, and try all the way to fix it like enable the “Hyper-V”, … but the error still persists. Then we could simply walkaround it by using the wsl version 1 “wsl — set-default-version 1”
2. Install Windows Terminal
PS C:\Users\ADMIN> wsl
btnguyen@DESKTOP-UAIA29B:/mnt/c/Users/ADMIN$ uname
Linux
btnguyen@DESKTOP-UAIA29B:/mnt/c/Users/ADMIN$ uname -a
Linux DESKTOP-UAIA29B 4.4.0-19041-Microsoft #2311-Microsoft Tue Nov 08 17:09:00 PST 2022 x86_64 x86_64 x86_64 GNU/Linux
btnguyen@DESKTOP-UAIA29B:/mnt/c/Users/ADMIN$
3. Setup the Linux machine
- Install the development packages including gcc, g++ and make
sudo apt update
sudo apt install build-essential
sudo apt install gdb
gcc --version
gdb --version
- Setup Home directory
export LINUX_HOME=/mnt/h/DEVELOPER/Linux
echo $LINUX_HOME
cd $LINUX_HOME
Note :
However, the variables defined using this method are stored for the current session only. They won’t be available for the next session.
To make the LINUX_HOME variable persistent, edit the file .bashrc and define its value in it.
vi ~/.bashrc
//Add the below command at the end of the file .bashrc
export LINUX_HOME=/mnt/h/DEVELOPER/Linux
// For the changes to take effect, update the .bashrc file using the source command:
source .bashrc
4. Hello World
Now the Linux machine is well setup, it’ll use the same hard drives with Windows.
PS C:\Users\ADMIN> wsl
btnguyen@DESKTOP-UAIA29B:/mnt/c/Users/ADMIN$ cd $LINUX_HOME
btnguyen@DESKTOP-UAIA29B:/mnt/h/DEVELOPER/Linux$ cd prog
btnguyen@DESKTOP-UAIA29B:/mnt/h/DEVELOPER/Linux/prog$ ls -ltr
total 0
-rwxrwxrwx 1 btnguyen btnguyen 103 Aug 26 16:25 test.cpp
btnguyen@DESKTOP-UAIA29B:/mnt/h/DEVELOPER/Linux/prog$ cat test.cpp
#include <stdio.h>
int main(int argc, char** argv)
{
printf ("Hello world\n");
return 0;
}
btnguyen@DESKTOP-UAIA29B:/mnt/h/DEVELOPER/Linux/prog$ gcc test.cpp -o test
btnguyen@DESKTOP-UAIA29B:/mnt/h/DEVELOPER/Linux/prog$ ls -ltr
total 12
-rwxrwxrwx 1 btnguyen btnguyen 103 Aug 26 16:25 test.cpp
-rwxrwxrwx 1 btnguyen btnguyen 8304 Aug 26 16:25 test
btnguyen@DESKTOP-UAIA29B:/mnt/h/DEVELOPER/Linux/prog$ ./test
Hello world
btnguyen@DESKTOP-UAIA29B:/mnt/h/DEVELOPER/Linux/prog$