Bash Installation

Installing Bash on different operating systems

⚙️ Installing Bash

Bash comes pre-installed on most Linux and macOS systems. Windows users can install Bash through WSL, Git Bash, or Cygwin. Verify your installation by checking the version number in your terminal.


# Check Bash version
bash --version
                                    

Output:

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

Installation by Platform

🐧

Linux

Pre-installed on most distributions

# Already installed
bash --version
🍎

macOS

Included by default (zsh is default shell)

# Switch to Bash
chsh -s /bin/bash
🪟

Windows

Install via WSL or Git Bash

# Enable WSL
wsl --install
🔄

Update

Keep Bash up to date

# Update on Linux
sudo apt update

🔹 Linux Installation

Most Linux distributions include Bash as the default shell, requiring no additional installation. If missing, install using your distribution's package manager: sudo apt install bash on Ubuntu/Debian or sudo dnf install bash on Fedora/CentOS. Verify installation with bash --version. Linux provides the most native Bash experience with complete feature support, regular security updates, and extensive documentation. The widespread adoption on servers and development environments makes Bash proficiency valuable for system administration and DevOps roles.


# Check if Bash is installed
which bash
bash --version

# Install on Ubuntu/Debian
sudo apt update
sudo apt install bash

# Install on Fedora/RHEL
sudo dnf install bash

# Install on Arch Linux
sudo pacman -S bash

# Verify installation
bash --version
                            

Output:

/bin/bash
GNU bash, version 5.1.16(1)-release

🔹 macOS Installation

macOS includes Bash, though newer versions default to zsh while maintaining Bash compatibility. Check your current shell with echo $SHELL and switch with chsh -s /bin/bash. Update to newer Bash versions using Homebrew with brew install bash. macOS's Unix foundation ensures full Bash functionality while providing seamless integration with Apple's developer tools and ecosystem. Many developers prefer Bash for scripting consistency across platforms and extensive online resources addressing macOS-specific considerations and optimizations.


# Check current shell
echo $SHELL

# Check Bash version
bash --version

# Install latest Bash with Homebrew
brew install bash

# Add new Bash to allowed shells
sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells'

# Change default shell to Bash
chsh -s /usr/local/bin/bash

# Verify change
echo $SHELL
                            

Output:

/bin/zsh
GNU bash, version 3.2.57(1)-release
/usr/local/bin/bash

🔹 Windows Installation (WSL)

Windows Subsystem for Linux provides a genuine Bash environment within Windows 10/11. Enable WSL via "Turn Windows features on or off" or with wsl --install in PowerShell. Choose Ubuntu, Debian, or other distributions from Microsoft Store. WSL2 offers full Linux kernel compatibility, performance improvements, and seamless file system integration. This solution provides the most authentic Bash experience on Windows, ideal for developers, students, and professionals needing complete Linux toolchains while maintaining Windows productivity applications.


# Open PowerShell as Administrator and run:
wsl --install

# Install specific distribution
wsl --install -d Ubuntu

# Check WSL version
wsl --list --verbose

# Update WSL
wsl --update

# Launch Bash
wsl

# Inside WSL, verify Bash
bash --version
                            

Output:

Installing: Ubuntu
Ubuntu has been installed.
GNU bash, version 5.1.16(1)-release

🔹 Windows Installation (Git Bash)

Git Bash delivers a lightweight Bash emulation environment for Windows without WSL requirements. Included with Git for Windows, it provides core Bash commands, SSH client, and basic Unix utilities. While not a complete Linux environment, Git Bash handles most scripting needs, version control operations, and command-line development tasks. Its minimal resource requirements and quick setup make it ideal for users needing essential Bash functionality for git operations, basic scripting, and cross-platform compatibility testing without full Linux subsystem overhead.

Installation Steps:

  1. Download Git for Windows from git-scm.com
  2. Run the installer and follow the setup wizard
  3. Select "Git Bash Here" option during installation
  4. Launch Git Bash from Start Menu or right-click context menu
  5. Verify installation with bash --version

# After installation, open Git Bash and verify
bash --version
git --version

# Test basic commands
pwd
ls
echo "Git Bash is working!"
                            

Output:

GNU bash, version 4.4.23(1)-release
git version 2.42.0.windows.1
Git Bash is working!

🔹 Verifying Installation

After installing Bash, verification ensures proper configuration and functionality. Check the version with bash --version, confirm the shell with echo $SHELL, and test basic commands like ls, cd, and pwd. Create a simple script with shebang line and execute it to confirm interpreter recognition. Thorough verification identifies installation issues early, confirms expected behavior, and builds confidence that your environment supports the scripting and command-line tasks you plan to undertake.


# Check Bash version
bash --version

# Check Bash location
which bash
whereis bash

# Check if Bash is your current shell
echo $SHELL

# Test basic Bash functionality
echo "Hello from Bash!"
date
whoami

# Check Bash features
bash -c 'echo "Bash is working: $BASH_VERSION"'
                            

Output:

GNU bash, version 5.1.16(1)-release
/bin/bash
/bin/bash
Hello from Bash!
Wed Oct  8 14:30:22 UTC 2025
john
Bash is working: 5.1.16(1)-release

🔹 Setting Bash as Default Shell

Configure Bash as your default shell to automatically start Bash sessions when opening terminals. Use chsh -s /bin/bash on Linux/macOS or select Bash as default in terminal preferences. This ensures consistent environment variables, aliases, and startup scripts across all terminal sessions. Changing default shells affects login behavior, script compatibility, and available features. Verify the change with echo $SHELL and test startup files to ensure your customizations load correctly in the new default environment.


# View available shells
cat /etc/shells

# Change default shell to Bash
chsh -s /bin/bash

# Or specify full path
chsh -s $(which bash)

# Verify the change
echo $SHELL

# Check current shell
ps -p $$

# Restart terminal for changes to take effect
                            

Output:

/bin/sh
/bin/bash
/bin/zsh
Shell changed to /bin/bash
/bin/bash

🧠 Test Your Knowledge

Which command checks your Bash version?