Setup Bash on Windows: My environment configuration

November 17, 2016

Inspired by some recent conversations on Twitter, I’ve decided to give Bash on Windows another shot. This post contains the steps I’ve taken to install and configure Bash on Windows to closely resemble my Linux / Mac settings for JavaScript and node development (with some extra steps I’ve taken for Ruby, etc at the end).

1. Enable Bash on Windows

Bash on Windows requires the Anniversary update of Windows 10. Please make sure you have that before continuing. To determine what version of Windows you are running, open a command prompt window and type winver. If you see Version 1607, you should be good to proceed (thanks Josh Pollard).

Windows Version dialog

Once that’s all set go to Settings -> Update & Security -> For Developers and enable Developer mode. Finally, go to Windows Features and enable Windows Subsystem for Linux. Your computer should restart and you should be able to run Bash for Windows at this point.

Windows features dialog

See Scott Hanselman’s blog or Stefan Roth’s post on TechNet for more on this.

2. Update apt-get

We are going to be installing some things and it would be good to make sure we’re up-to-date here. Launch bash by pressing the Windows key and typing bash. From there, apt-get update should obtain the latest package information. If you are running into issues with IPv6 vs IPv4 checkout this post on Ask Ubuntu or here on BruteForce labs.

3. Install nvm

nvm stands for Node version manager and is an essential part of my development environment. Using nvm allows you to switch what version of node you’re using on a project by project basis. To install nvm, run curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash (from the nvm documentation) followed by Source .bashrc

4. Install git

Take the following steps to install git on Bash for Windows and be ready to work with projects on GitHub.

  1. apt-get install git (see GitHub’s guides for more on this)
  2. Generate an access token or a SSH key (and associate the key to your GitHub account)

5. Setup bash git prompt

bash-git-prompt is, as the project describes, “An informative and fancy bash prompt for Git users” — that is, it shows git information for the current repository when navigating to project folder.

To install bash-git-prompt:

  1. cd ~
  2. git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt --depth=1
  3. Add GIT_PROMPT_ONLY_IN_REPO=1 to .bashrc

Read through the documentation as there is a bit of configuration and themeing that’s possible. That said, I’m running with the default for now.

6. Make Visual Studio Code use Bash

It’s possible to toggle a terminal inside Visual Studio Code — by default, this appears to be the standard command prompt. Thankfully, Paul DeCarlo created a blog post explaining that you can add "terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe" to your user settings to use Bash as the default instead.

It should look like this if everything is working correctly:

Visual Studio code window

Extras

Install tmux

tmux is a terminal multiplexer that lets you run multiple programs in one terminal (it does a lot more than that but read the docs for more info). I frequently use tmux to run tests while running webpack server, React Storybook, or something else along those lines.

You can install tmux by running apt-get install tmux. Once tmux is installed on the system you can press ctrl + b + c to create a new window and ctrl + b + w to list the windows. See this tmux cheatsheet for more

Install Ruby and Rails

I do a bit of Ruby work and highly recommend rbenv for multiple ruby versions. Digital Ocean’s guide to installing ruby / rbenv is great AND it works on Bash for Windows.

Setup vim and Vundle

I use Vim quite a lot and Vundle for managing vim plugins.

  1. git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
  2. Setup your .vimrc (here’s my .vimrc for example)
  3. Run vim and type :PluginInstall

Install cmder

Cmder is a nice console emulator for Windows. You can run bash in cmder by typing bash from the prompt. You may have to type cd ~from there to get back to your standard bash home directory.

The End

Please feel free to let me know of any questions or feel free to submit a PR or issue on anything that’s mistaken here :)


Ryan Lanciaux

Hi 👋 I'm Ryan Lanciaux. I run Spaceship Studio, LLC. a consultancy specializing in fast and dynamic web and native mobile applications.

I live in Ann Arbor with my wonderful family! In my freetime, I create electronic music.

You should follow me on Twitter