This section may not be up to date with the latest versions of Windows. Please see https://docs.microsoft.com/en-us/windows/wsl/install-win10
This is available in Windows 10 as of the Anniversary Update.
Press
WinKey+R
, typewinver
and press ENTER
If the version number reads1607
, then you have the Anniversary Update installed. The bash subsystem will useUbuntu 14.04
If the version number reads1703
, then you have the Creators Update installed. The bash subsystem will useUbuntu 16.04
To enable bash:
- Turn on Developer mode in Settings > Update & security > For developers
- Open Control Panel > Programs > Turn Windows features on or off
- Enable Windows Subsystem for Linux (Beta)
- Open the command prompt and type
bash
to install the linux subsystem
Do not change Linux files using Windows apps and tools
- DO store files in your Windows filesystem that you want to create/modify using Windows tools AND Linux tools
- DO NOT create / modify Linux files from Windows apps, tools, scripts or consoles
Do not use the default-jre and default-jdk packages, as those use the OpenJDK/JRE vendor. We want to use the Oracle vendor.
See https://stackoverflow.com/a/45608467/3033899
By default, the linux $PATH will include everything in the windows path. Add this to the .bashrc file to remove specific paths from $PATH.
### remove unnecessary Win PATHs
# This can prevent extension-less commands from bleeding into BASH.
# (eg. "ng" would execute the Win bin if "@angular/cli" wasn't installed on Linux.)
#
function path_remove {
# Delete path by parts so we can never accidentally remove sub paths
PATH=${PATH//":$1:"/":"} # delete any instances in the middle
PATH=${PATH/#"$1:"/} # delete any instance at the beginning
PATH=${PATH/%":$1"/} # delete any instance at the end
}
#path_remove '/mnt/c/Users/me/AppData/Roaming/npm'
#path_remove '/mnt/c/Program Files/Git'
#path_remove '/mnt/c/Program Files/Git/cmd'
path_remove '/mnt/c/Program Files (x86)/nodejs'
#path_remove '/mnt/c/OpenSSL-Win32/bin'
path_remove '/mnt/c/Python27'
path_remove '/mnt/c/Python27/Scripts'
path_remove '/mnt/c/Program Files/MongoDB/Server/3.2/bin'
path_remove '/mnt/c/Program Files/Apache Software Foundation/apache-maven-3.3.3/bin'
To see which paths actually need to be removed:
- Comment out all the calls to
path_remove
- Execute
. .bashrc
to apply any changes to.bashrc
- Execute
echo $PATH
to see the current state of the linux path- Execute
echo "$PATH" | tr ':' '\n' | sort
to put each item on its own line and sort
- Execute
- Update the calls to
path_remove
to specify paths to be removed (each one must be specified - children of that path are not included)
Create a file called .bash_aliases in the same folder as .bashrc
Add all aliases to this file, like so:
alias cmd='/mnt/c/Windows/System32/cmd.exe'
alias ccmd='cmd /C "start cmd /K $@"' # Executes any command in a new cmd window
alias winhome='cd /mnt/c/Users/me'
alias dev='cd /mnt/c/dev'
Consider adding programs to the Windows path (which should automatically be included in the linux path too) before creating an alias for a program.
Follow the installation steps for nvm (install steps)
Close the bash terminal and open it again. Type command -v nvm
and it should print nvm
(verify installation)
Use nvm to install node (nvm usage)
If this causes the shell to take several seconds to open, please update the nvm portion of .bashrc
as suggested in the latest comments here nvm-sh/nvm#1277.
nvm seems to have slowness issues right now, so this might be a more favorable approach. The downside is that you will have to do updates by following these steps again.