Bash Installation

Bash comes preinstalled on most Linux systems and older macOS versions. Windows users can add it through a small setup step. A working Bash shell takes only a few minutes to prepare on any computer.

Check If Bash Already Exists

Open a terminal window and type the command below. The shell prints its version when Bash is present.

bash --version

Sample output:

GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)

A version number of 4.0 or higher supports every topic in this course. Version 3.2 ships with older macOS machines and misses a few features such as associative arrays.

Installation Paths at a Glance

+-----------------------------------------------------------+
|                  Where Do You Run Bash?                   |
+-----------------------------------------------------------+
|                                                           |
|   Linux    --->  Already installed (update if needed)     |
|                                                           |
|   macOS    --->  Installed (version 3.2) --> upgrade      |
|                  with Homebrew for version 5              |
|                                                           |
|   Windows  --->  WSL (full Linux) or Git Bash (light)     |
|                                                           |
+-----------------------------------------------------------+

Install or Update on Linux

Every popular Linux distribution includes Bash. Run the matching command to install or refresh it.

Ubuntu and Debian

sudo apt update
sudo apt install bash

Fedora and Red Hat

sudo dnf install bash

Arch Linux

sudo pacman -S bash

Install on macOS

Apple ships Bash 3.2 with macOS because of licensing rules. Homebrew delivers a modern version in two commands.

brew install bash
/opt/homebrew/bin/bash --version

Intel-based Macs store the new file at /usr/local/bin/bash. Apple Silicon Macs store it at /opt/homebrew/bin/bash.

Make the New Version Your Default

Add the new path to the list of allowed shells and switch to it:

echo /opt/homebrew/bin/bash | sudo tee -a /etc/shells
chsh -s /opt/homebrew/bin/bash

Install on Windows

Windows offers two reliable options.

Option 1: Windows Subsystem for Linux (WSL)

WSL runs a real Linux system inside Windows. Open PowerShell as administrator and type:

wsl --install

Restart the computer when the installer asks. Ubuntu opens afterward and offers a Bash prompt right away.

Option 2: Git Bash

Git for Windows includes a lightweight Bash window. Download Git from its official website, run the installer, and pick Git Bash from the Start menu. Git Bash suits quick practice, while WSL suits serious scripting work.

Confirm the Setup Works

Type these lines in the terminal. A successful setup prints the text and the current shell path.

echo "Bash is ready"
echo $SHELL

Output:

Bash is ready
/bin/bash

A different path such as /bin/zsh means the terminal uses another shell. Type bash and press Enter to start Bash inside it.

Pick a Text Editor

A script is a plain text file, so any editor works. Popular choices include:

  • nano offers a simple editor inside the terminal. It suits beginners.
  • VS Code highlights colors and catches typing mistakes with the ShellCheck extension.
  • vim gives experienced users fast keyboard-driven editing.

Open nano with a new file using this command:

nano hello.sh

Press Ctrl+O to save and Ctrl+X to exit.

Common Setup Problems

Command Not Found

The message bash: command not found means the system cannot locate a program. Check spelling first. Run which bash to see the file location.

Permission Denied

Installation commands need administrator rights. Add sudo in front of the command and type your password.

Old Version Still Shows

Open a new terminal window after an upgrade. An old window keeps the previous shell loaded.

Key Takeaways

  • Linux includes Bash by default.
  • macOS ships an old version, and Homebrew upgrades it.
  • Windows users run Bash through WSL or Git Bash.
  • Run bash --version to check the installed version.
  • Use any text editor to write scripts.