Skip to content

0xmoei/Install-Linux-on-Windows

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 

Repository files navigation

Install Linux Ubuntu on Windows using WSL

In this Guide, I'll tell you how to Install Linux (Ubuntu distribution) on Windows using WSL

Step 1: Enable WSL 2

  1. Opening Windows Powershell Terminal Screenshot_357

  2. Enable WSL

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  1. Run the WSL Installation Command:
wsl --set-default-version 2
wsl --install
  • It may ask you to choose a username and password
  1. Reboot Computer:

After the installation completes, you may need to reboot your computer

Step 2: Install Ubuntu

  1. Open Microsoft Store:

After restarting, open the Microsoft Store from the Start menu.

  1. Search for Ubuntu:

In the Store, type "Ubuntu" in the search bar. You’ll see various versions like Ubuntu 20.04 LTS, Ubuntu 22.04 LTS, etc

  1. Select and Install:

Click on the version you want to install, then click the Get or Install button

Step 3: Set Up Ubuntu

  1. Launch Ubuntu:
  • Once installed, you can launch it directly by searching for "Ubuntu" in the Start menu
  • The first time you launch Ubuntu, it will take a moment to set up. After that, you will be prompted to create a new user account and password

Step 4: Install and Update Packages (aka Drivers)

  1. Update and Upgrade default Packages
sudo apt update

sudo apt upgrade
  1. Install more important packages
sudo apt install curl iptables build-essential git wget lz4 jq make gcc nano automake autoconf tmux htop nvme-cli pkg-config libssl-dev libleveldb-dev tar clang bsdmainutils ncdu unzip libleveldb-dev  -y
  1. Install Docker
sudo apt update -y && sudo apt upgrade -y
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update -y && sudo apt upgrade -y

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Docker version
docker --version

Optional: To install more packages you can check my recent Linux guide

Optional: Change user

There are 2 ways to login to ubuntu:

    1. You are root (administrator with full permissions)
    1. you are an specific user with specific permissions

You see by entering whoami, I am logged in as user:mirana

image

If you want to login with root (full permissions):

sudo su

image

  • Now you see I am as root user, but in mirana user main directory
  • I need to type cd to move to the main directory of root

To login to a specific user again, Enter this command: su - username

Access Ubuntu directories in Windows explorer

To go to your Ubuntu directory using Windows explorer, Enter this in Windows Explorer Addressbar

\\wsl$
  • home: main directory of your specific user
  • root: main directory of your root user image

If you don't have access to root directory, Enter this command in terminal sudo chmod 755 /root

Give a user sudo access

If you are not root, switch to root first (from Windows PowerShell):

wsl -d Ubuntu -u root

Or from Ubuntu if you already have sudo:

sudo su

If needed, create the user, then add to the sudo group and set a password:

id -u <username> 2>/dev/null || adduser <username>
adduser <username> sudo
passwd <username>

# verify
groups <username>

Optional: enable passwordless sudo for the user (use one of the following):

# safer (uses visudo)
visudo -f /etc/sudoers.d/<username>
# add this single line and save
<username> ALL=(ALL) NOPASSWD:ALL

Or as commands:

echo '<username> ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/<username>
chmod 440 /etc/sudoers.d/<username>

Optional: make the user the default for your Ubuntu WSL distro (run in Windows PowerShell):

ubuntu.exe config --default-user <username>

Note: the executable may be named ubuntu2004.exe, ubuntu2204.exe, etc., depending on your distro.

Connect to Ubuntu from Windows tools (Cursor, MobaXterm, etc.)

  • Cursor

    • Open folder via WSL share: File > Open Folder > enter \\wsl$\Ubuntu\home\<username>\<project>
    • Or install the "Remote - WSL" extension in Cursor, then use Command Palette: "Remote-WSL: New WSL Window" and open your folder inside WSL
  • MobaXterm

    • WSL session: Session > WSL > select your distro (e.g., Ubuntu) > OK
    • SSH session (optional): install and start SSH inside WSL, then connect from MobaXterm
sudo apt update && sudo apt install -y openssh-server
# enable systemd in WSL if not already enabled
sudo tee /etc/wsl.conf >/dev/null <<'EOF'
[boot]
systemd=true
EOF
exit

From Windows PowerShell:

wsl --shutdown

Back in Ubuntu:

sudo systemctl enable --now ssh
hostname -I  # use this IP in MobaXterm, port 22
  • Windows Terminal / PowerShell
wsl -l -v                 # list distros
wsl -d Ubuntu             # open Ubuntu
wsl -d Ubuntu -u <user>   # open as a specific user

About

Instructions for Installing Linux (Ubuntu Distribution) on Windows using WSL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published