Chromium in WSL2
The walkthrough here works for any applications that rely on “snap” for installation. If you want to install “packageXYZ”, I assume you are smart enough to replace “chromium” with “packageXYZ”.
Note: The assumption here is that you are running a debian-based WSL2 installation such as Ubuntu. For Arch, I may make a followup post.
Two steps (mostly): (1) Install the package using “apt”. (2) Install additional package(s) using “snap”.
(1) Install the package using apt:
sudo apt install chromium-browser
(2) Install additional packages using “snap”. Yes, this is a separate step from "apt install":
sudo snap install chromium
You may see an error that says the following:
“System has not been booted with systemd as init system (PID 1).
Can't operate. Failed to connect to bus: Host is down”
Reason:
“snap” is already bundled with your Ubuntu installation on WSL2. snap uses “snapd”, which relies on “systemd” or “systemctl”. We are just going to assume “systemd” instead of “systemctl” (you should research and find out why is it so :)
"systemd" is not natively started in WSL2 environment. This is a known issue and the workaround is to make sure "systemd" starts during the WSL2 bootup.
Workaround for systemd:
In your WSL2 terminal, create a "wsl.conf" file in "/etc" folder:
sudo -e /etc/wsl.conf#Any editor of your choice is just fine.
This opens a blank document. Add the following lines to start the "systemd" on reboot.
[boot]
systemd=true
Save the "/etc/wsl.conf" file with the newly added lines.
Close your WSL2 terminal.
Next, we need to reboot the WSL2. Closing the WSL2 window is merely not enough. Open windows powershell and turn off the WSL2.
wsl --shutdown
Wait for a minute or two, then open your WSL2. If there were not any issues, systemd will be up and running. You can check that using:
sudo systemctl status
Lets get back to chromium.
Now chromium is ready to be installed. Remember we need snap to install additional packages for chromium. Assuming that you have already run "sudo apt install chromium-browser", run the following.
sudo snap install chromium #yes, not chromium-browser this time. Just chromium.
You can open chromium from the terminal using just "chromium". If your WSL2 does not recognize the "chromium" command, it most likely does not recognize chromium because it cannot find chromium in the path.
Add chromium to the path by editing the ~/.bashrc.
sudo gedit ~/.bashrc #nano or vim will work just fine here.
Add chromium to the PATH by appending the following line at the end of ~/.bashrc. Chromium binary is by default installed at "/usr/bin/chromium-browser". You may have to double-check that you can find the binary in "/usr/bin/".
export PATH="$PATH:/usr/bin/chromium-browser" #DO NOT CHANGE EXISTING LINES CONCERNING THE PATH VARIABLE. JUST ADD THE LINE AT THE END.
Save the changes to "~/.bashrc" and push the changes by running
sudo source ~/.bashrc
You can start the chromium browser by just typing in "chromium" in the terminal.