Editing .bashrc in WSL safely

14,062

Solution 1

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.

Solution 2

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.

Solution 3

If you prefer a GUI editor then install VcXsrv as detailed here:

Then use gedit ~/.bashrc

Solution 4

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.

Share:
14,062

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    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?

  • Dr Jyy
    Dr Jyy over 2 years
    Fyi. Complains, asking for WSL2