WSL ubuntu zsh nvm etc.
Tags: ubuntu, bash, vscode
Published: 2019-10-14 15:13:36

The Windows Subsystem for Linux (WSL) seems to be mature enough now to give it another shot. Copy and paste, and other simple annoyances that kept me away before are working better. Also, I've been reading that [nvm](https://github.com/creationix/nvm "Node Version Manager") (Node Version Manager) works now, so here goes.

The following has been tested on Windows 10 Professional (version 1709, build 16299.309) with WSL enabled and Ubuntu installed from the [Windows Store](https://aka.ms/wslstore "Windows Store | WSL"). It's also working fine on the current May 2019 Update, version 1903.

### Ubuntu Update

If it has been a while, first thing I like to do with the Ubuntu app is update and upgrade the ubuntu Linux packages. First update the package database with `apt-get update`, then upgrade with `apt-get upgrade` or `apt-get dist-upgrade`. I prefer `apt-get dist-upgrade` since it will remove obsolete packages and add new ones as needed.

> Windows update does not change the WSL Ubuntu installation. To upgrade to a new release, run `sudo do-release-upgrade` in the Ubuntu Terminal.

### Oh My Zsh

Oh My Zsh will spruce up your Ubuntu bash and add some additional functionality. Here is a screenshot of my Ubuntu app to illustrate.

![WSL Ubuntu bash example oh-my-zsh cowsay etc.](https://thepracticaldev.s3.amazonaws.com/i/h3bxllvc2a2ji6csujf7.png)

Install Oh My Zsh just as you would on any other ubuntu system. Note that Zsh is a pre-requisite. For installation instructions and more information, visit [https://github.com/robbyrussell/oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh).

Your going to want to change the font to fix unknown character issues. I've installed the DejaVu Sans Mono for Powerline font available [here](https://github.com/powerline/fonts "Powerline Fonts").

![WSL Ubuntu bash font properties](https://thepracticaldev.s3.amazonaws.com/i/vg6pqapkwin7ee2095td.png)

> To set WSL Ubuntu bash with zsh as your integrated terminal in [VS Code](https://jimfrenette.com/code-editors/visual-studio-code/). Update your user settings file, e.g., `%appdata%\Code\User\settings.json` with the following.

##### settings.json

```javascript
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe",
"terminal.integrated.shellArgs.windows": ["-c", "zsh"]
```

### ssh

If you want to use your existing git and/or other ssh keys, copy them from their folder in Windows into a `.ssh` folder under ubuntu. For example,

    cd ~/
    mkdir .ssh
    
    # navigate to Windows .ssh folder, e.g.,
    cd ../mnt/c/Users/Gilfoyle/.ssh
    
    # copy the keys into ubuntu .ssh folder
    cp id_rsa ~/.ssh/
    cp id_rsa.pub ~/.ssh/
    
    # set permissions on the private key for github
    chmod 600 ~/.ssh/id_rsa
    

### nvm

nvm is a utility for installing and managing multiple versions of node.js.

Install as an Oh My ZSH! custom plugin by cloning `zsh-nvm` into your custom plugins repo.

    cd ~/.oh-my-zsh/custom/plugins
    
    git clone https://github.com/lukechilds/zsh-nvm ~/.oh-my-zsh/custom/plugins/zsh-nvm
    

Then load as a plugin in your `.zshrc` profile. Note that plugins need to be added before `oh-my-zsh.sh` is sourced. For example, here is a snippet from my `.zshrc` profile.

##### .zshrc

    # Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
    # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
    # Example format: plugins=(rails git textmate ruby lighthouse)
    # Add wisely, as too many plugins slow down shell startup.
    plugins=(git)
    
    plugins+=(zsh-nvm)
    
    source $ZSH/oh-my-zsh.sh
    

> If you want to install [Yarn](https://yarnpkg.com), use `apt-get install --no-install-recommends yarn`. By default, Yarn installs nodejs as a system-wide dependency.

After updating your `.zshrc` profile to load the `nvm` plugin, close and re-open the Ubuntu app and to install nvm when the plugin is loaded for the first time.

One the install has completed, you can verify by running `nvm` which should output the `nvm --help` contents.

Install the latest LTS version of Node.js which at the time of this writing is version 8.11.1

    # install node
    nvm install 8.11.1	
    

> If you want to upgrade npm, use `nvm install-latest-npm`.

### etc.

[Bash-Snippets](https://github.com/alexanderepstein/Bash-Snippets) collection of bash scripts.

    apt-get install fortune
    
    apt-get install cowsay
    
    apt-get install htop
    

#### Mount

Mount a drive such as a USB flash drive formatted as FAT, ExFAT or NTFS. For example, a drive listed as `F:\` in Windows would be mounted as follows.

    mkdir /mnt/f
    mount -t drvfs f: /mnt/f
    

#### Bind

Bind a custom mount for any drives you want to access. For example, the `C` drive. This is also required should you want to use Docker volume mount paths as described in [this post by Nick Janetakis](https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly "Setting Up Docker for Windows and WSL to Work Flawlessly").

**Windows 10 17.09**

    mkdir /c
    mount --bind /mnt/c /c
    
    # unmount
    umount /mnt/c
    

> Included in Windows 10 version 1803 (April 2018 Update) is support for WSL launch configuration. The `/etc/wsl.conf` file contains settings for drive mounting and network configuration. Read the Microsoft Developer blog post, [Automatically Configuring WSL](https://blogs.msdn.microsoft.com/commandline/2018/02/07/automatically-configuring-wsl/) for more information on how to use `wsl.conf`

**Windows 10 18.03 WSL Configuration File**

Create the `/etc/wsl.conf` file and set `root = /` so you can access drives with `/c` or `/e` instead of `/mnt/c` and `/mnt/e`.

##### wsl.conf

    [automount]
    root = /
    options = "metadata"
    

#### File System

If you want to browse the files using Windows Explorer and/or backup the root file system, the location of these files is in the hidden AppData folder. For example:

    %localappdata%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs
    

From [Rich Turners blog post](https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/) ...

![Do not change Linux files using Windows apps and tools](https://thepracticaldev.s3.amazonaws.com/i/0lckj2ggmyn8v0rxw130.png)


More info available at [WSL File System Support](https://blogs.msdn.microsoft.com/wsl/2016/06/15/wsl-file-system-support/).

#### Resources

*   [docs.microsoft.com/en-us/windows/wsl/install-win10](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
*   [github.com/robbyrussell/oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh)
*   [github.com/powerline/fonts](https://github.com/powerline/fonts)
*   [github.com/creationix/nvm](https://github.com/creationix/nvm)

Originally published at [jimfrenette.com/2018/04/wsl-ubuntu-zsh-nvm-etc](https://jimfrenette.com/2018/04/wsl-ubuntu-zsh-nvm-etc/)