Set Up Your Language · 3 of 14
Setting Up Bash / Shell
Bash is a shell: a program that runs commands you type, and that can run a list of commands saved in a file (a shell script). It is the standard on Linux and Mac, and on almost every web server. Windows does not include Bash, so we install Git for Windows, which brings a ready-made Bash called Git Bash (and Git, a tool for keeping versions of your code, which you will want later anyway).
New to all this? Read Before you start on the main page first: it shows how to open Terminal, make a folder for your code, and see file name endings. It takes five minutes and prevents most problems.
1 What to download, and from where
Download only from git-scm.com, the official Git website. Other download sites can bundle unwanted software.
- Go to git-scm.com/downloads/win.
- Click the link for the latest 64-bit Git for Windows Setup. The download starts (a file named like
Git-2.x.x-64-bit.exe).
2 Install it on Windows
- Open the downloaded file. If Windows asks whether to allow changes, click Yes.
- The installer shows many screens with options. You can keep every default: just click Next on each one, then Install.
- On the last screen, untick View Release Notes and click Finish.
- Press the Windows key, type Git Bash and open it. A window opens with a
$sign: that is Bash waiting for a command.
Another way: Windows can run real Linux inside it with WSL (Windows Subsystem for Linux). Open Terminal as administrator and type wsl --install, then restart. It is a bigger download and asks you to create a Linux user name and password. Git Bash is enough for learning.
3 Check that it worked
In the Git Bash window, type this and press Enter:
bash --versionWhat you will see: A first line starting with GNU bash, version and some more lines about the licence.
GNU bash, version 5.2.37(1)-release (x86_64-pc-msys)
If you see an error such as "is not recognized" instead, look at the common mistakes at the bottom of this page.
4 Write and save your first program
A program is just a text file. You can write it in Notepad, which comes with Windows. (Later you may like the free Visual Studio Code editor from code.visualstudio.com, which colours the code and helps spot mistakes.)
- Open Notepad (press the Windows key, type Notepad, press Enter).
- Type the program below, or click Copy and paste it in with Ctrl + V. Every symbol matters, so copy it exactly.
#!/bin/bash echo "Hello, World!" - In Notepad choose File → Save as. Go to your
C:\codefolder. Set Save as type to All files (*.*), type the file namehello.shexactly as shown, including the dot and the ending, and click Save.
The first line tells the computer that this file is a Bash script. echo prints the text after it.
Do not use Word. Word saves extra formatting and changes straight quotes " into curly ones “ ”, which no programming language accepts.
5 Run it and see the result
Bash needs its own window. Open Git Bash and move into your folder with the line below. Bash writes Windows folders differently: C:\code becomes /c/code, with forward slashes.
Type these lines one at a time, pressing Enter after each:
cd /c/code
bash hello.shWhat you will see: the words below on a new line. That is your program running.
Hello, World!
Congratulations: you have written and run a Bash program.
6 Common beginner mistakes and how to fix them
Error messages look alarming but are usually precise: read the first line, and look for a line number. If you are stuck, copy the whole error message and paste it into an AI assistant along with your code, and ask what it means.
$'\r': command not found
Why: Windows ends each line of text with two hidden characters; Linux-style Bash expects one, and complains about the extra \r.
Fix: in Git Bash run dos2unix hello.sh (it comes with Git for Windows), then run the script again. If you edit with VS Code, click CRLF at the bottom right and change it to LF before saving.
bash: cd: C:code: No such file or directory
Why: in Bash a backslash \ means something special, so cd C:\code does not work.
Fix: use forward slashes and the Bash form of the drive: cd /c/code. Or, in File Explorer, right-click inside the folder and choose Open Git Bash here (on Windows 11 it may be under Show more options).
bash: !": event not found
Why: when you type echo "Hello, World!" directly at the $ prompt (not in a file), Bash treats ! as a shortcut to repeat old commands.
Fix: use single quotes when typing directly: echo 'Hello, World!'. Inside a script file, double quotes work fine.