The Command Line on Windows / Installing Bash

The Command Line on Windows / Installing Bash#

In our next reading on Command Line Basics, we’ll learn that there are actually several programs available that allow users to interact with their operating system via text commands instead of using their mouse to click on icons (feel free to follow the link and read ahead if you’d like).

In this course, we’ll focus on learning bash because it’s so ubiquitous in the data science space. Why? Mostly because it is the default command line tool for Linux operating systems, and while you may not know it, most of the computers you interact with on a daily basis run Linux. Your personal computer may be a Mac (which also uses bash by default) or a Windows computer, but the computers running websites, managing your email, running those ticket kiosk you see at the airport, etc. are almost all running on Linux. So when you start doing cloud computing, you’ll probably be working with a Linux virtual machine. So if you’re going to learn a command line tool as a data scientist, bash is the natural choice.

But: bash is not the default on Windows (Windows uses PowerShell and CMD by default), so on this page, I’ll show you how to set up a system that lets you work with bash on your Windows computer.

Install Cmder#

To get a good bash interface in Windows, begin by downloading Cmder from their main site.

Make sure to select the Full Install (or you won’t get Bash)!

Then unzip the downloaded Cmder file and place it in your user folder (e.g. C:\Users\[your user name\Cmder. Mine is in C:\Users\Nick\Cmder). DON’T try and put it in ProgramFiles.

Configure Cmder#

Once installed, you’ll find you a new program called Cmder available! By default, Cmder is a kinda of hybrid interface that lets you use most commands people use in bash and the commands people use when working with the default Windows command line tool (CMD). This is nice for people with some windows command line experience, but it does mean that Cmder doesn’t quite work like bash.

With that in mind, we want to set Cmder to default to pure bash mode by clicking on Settings (the three horizontal bars on the bottom right), then changing the “startup task” to {bash::bash as Admin} (see pic below).

selectbash

Create Configuration File#

When you open a sh, bash, or zsh session, that session begins by running all the code in a special file the helps configure the session. Among the things done in these files, they often define “environment variables” – variables that are visible to any program run from your command line session, with information about things like where to find various programs, like Python.

bash in particular will run a file located in the bash’s home directory (which is include your Cmder folder) called .bash_profile. We don’t need to modify this right now, but we do want to create a file there for future use.

To do this, open a new bash session, then:

  • run the command cd ~: (~ is a shortcut for the bash home directory, so this makes the current bash directory your bash home directory.)

  • run the command touch .bash_profile: This will create a file called .bash_profile we can use later.

Integrate Cmder into VS Code#

If you want to use the integrated terminal in VS Code, you may wish to set that to use Cmder using these instructions!