Editing .bashrc in WSL safely
How do I edit the .bashrc
file in Windows Subsystem for Linux safely?
This article warns to never edit files stored in the WSL AppData
folder using Windows tools.
But then how do you edit files like .bashrc
in a safe manner?
Use the built-in nano
editor as:
nano ~/.bashrc
The most important shortcuts for nano
are Ctrl+O to save the file and Ctrl+X to close the editor.
A simple guide for using nano
can be found in the Gentoo Linux Wiki.
I think Visual Studio Code works fine. Just install the Remote - WSL extension.
To use it just open cmd and type bash
. In bash
type cd
, then use code .bashrc
.
Voila! VS Code opens in WSL and you can edit the files you want.
If you prefer a GUI editor then install VcXsrv
as detailed here:
- What's the easiest way to run GUI apps on Windows Subsystem for Linux as of 2018?
Then use gedit ~/.bashrc
Open Windows File Explorer and type \\WSL$
in the address bar. This will open a pseudo-share that WSL provides for each running WSL instance where it is safe to edit the files.
Note that the instance does need to be started and running for this to work.