How to Install and Use Bash on Windows 11

By | 2024-10-02

If you’re a developer or someone who frequently works with command-line tools, you might be familiar with Bash, the popular Linux shell. What if I told you that you can use Bash on your Windows 11 machine without having to install Linux? Thanks to the Windows Subsystem for Linux (WSL), running Bash on Windows is now possible—and it’s easier than ever! This guide will show you how to install and use Bash on Windows 11, even if you’re new to the world of command-line interfaces.

What Is Bash, and Why Use It on Windows?

Bash (short for “Bourne Again Shell”) is the default command-line shell for many Linux distributions. It allows users to interact with their system, run scripts, and perform tasks more efficiently. Having Bash on Windows gives you the power of Linux commands and tools right inside your Windows environment. This is great if you’re developing software or automating tasks that require a Linux-style environment.

Now, let’s jump into how to set it up on Windows 11.

Step 1: Enable Windows Subsystem for Linux (WSL)

The first thing you need to do is enable the Windows Subsystem for Linux (WSL), which allows Windows to run Linux binaries natively.

  1. Open PowerShell as an Administrator
    • Press Windows Key + S and type PowerShell.
    • Right-click on Windows PowerShell and choose Run as administrator.
  2. Enable WSL
    In the PowerShell window, type the following command and press Enter:
    wsl --install
    This command installs the necessary WSL components and downloads the latest Linux kernel.
  3. Restart Your Computer
    After the installation is complete, you’ll be prompted to restart your computer. Go ahead and restart to apply the changes.

Step 2: Install a Linux Distribution

Once WSL is enabled, you can install a Linux distribution (distro) of your choice, such as Ubuntu, Debian, or Kali. For this guide, we’ll use Ubuntu, which is widely supported and beginner-friendly.

  1. Open the Microsoft Store
    Press Windows Key + S, search for Microsoft Store, and open it.
  2. Search for Ubuntu
    In the Microsoft Store, type Ubuntu in the search bar, and select it from the list of results.
  3. Install Ubuntu
    Click the Get button to install the Ubuntu distribution on your Windows 11 machine. Once it’s installed, click Launch to start Ubuntu for the first time.
  4. Set Up Ubuntu
    When you first launch Ubuntu, you’ll be asked to set up a username and password. This creates your user account for the Linux environment. Make sure to remember the password, as you’ll need it for administrative tasks.

Step 3: Using Bash on Windows 11

Now that you’ve installed Ubuntu and WSL, you can start using Bash right from your Windows environment.

  1. Open Ubuntu
    You can open Ubuntu by searching for it in the Start menu or by simply typing Ubuntu in the search bar.
  2. Run Basic Bash Commands
    Now that you’re in the Bash terminal, you can start running Linux commands! Here are a few basic commands to try:
    • Update the package list:
      sudo apt update
    • Install a package (e.g., Git):
      sudo apt install git
    • Check the current directory:
      pwd
    • List files in a directory:
      ls
  3. Access Windows Files
    One of the coolest features of WSL is that you can easily access your Windows files from within Bash. To navigate to your Windows filesystem, go to /mnt/c/ which represents your C: drive. You can do this with the following command:
    cd /mnt/c

Step 4: Customize Your Bash Experience

Once you’re comfortable with using Bash on Windows 11, you can take it a step further by customizing your terminal environment.

  1. Install Additional Tools
    You can install common Linux tools and packages using apt, the package manager for Ubuntu. For example, to install the curl tool, run:
    sudo apt install curl
  2. Modify the Bash Profile
    You can customize your Bash environment by editing the .bashrc file. This file runs every time you open Bash and allows you to set aliases, customize the prompt, and more. To edit it, type:
    nano ~/.bashrc
  3. Install a Text Editor (Optional)
    If you prefer using a full-fledged text editor, you can install one like VS Code, which works seamlessly with WSL. Install it from the Microsoft Store, and you’ll be able to edit your Linux files from a graphical interface while still using the power of the Bash terminal.

Troubleshooting Common Issues

  1. “WSL not recognized” Error
    If you get an error saying “WSL is not recognized,” make sure you’re running PowerShell as an administrator and that you’ve restarted your computer after enabling WSL.
  2. Slow Performance
    If you notice that Bash is running slowly, you may need to allocate more system resources to WSL. You can configure this by editing the .wslconfig file to adjust memory and CPU usage.

Running Bash on Windows 11 with WSL opens up a world of possibilities for developers and power users. Whether you’re looking to run Linux scripts, develop software, or simply explore the Linux environment, WSL makes it all possible without leaving the comfort of Windows. By following this guide, you’ll have Bash installed and ready to go in no time!

Have any questions about using Bash on Windows? Drop them in the comments, and I’ll help you out!

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.