[Use it on Windows!] How to Install Bash with WSL (with Pictures)
In the last article, "What is Bash? A Beginner's Guide to the Shell and Its Power," we learned the basics of Bash, the program behind the black screen, and its powerful features. However, some web creators might have thought, "My main machine is Windows, so maybe Bash isn't relevant to me..." Don't worry! Today's Windows has stronger integration with Linux than ever before.
The key to this is what we're introducing today: WSL (Windows Subsystem for Linux). By using WSL, you can run a "real" Linux environment on top of Windows with surprising ease, and of course, you can use Bash freely. This allows you to develop and test in an environment identical to your web server (which is often Linux-based), dramatically improving your work efficiency and accuracy.
In this article, we'll walk through the steps to install WSL and build a Bash environment on Windows, with detailed explanations that serve as a substitute for screenshots, ensuring that even beginners won't get lost. The setup can be completed with just copy-and-paste commands, so let's experience "Bash running on Windows" together!
What is WSL (Windows Subsystem for Linux)?
Before we install WSL, let's briefly understand what it is.
In a nutshell, WSL is "a system for running Linux programs directly on Windows." It's an official feature developed by Microsoft, and you can imagine it as building a dedicated house for Linux right inside of Windows.
In the past, running a Linux environment on Windows typically required using heavy software like a "Virtual Machine," which emulates an entire separate PC inside your PC. However, WSL is far more lightweight than a virtual machine and starts up in an instant. It can also easily access the Windows file system, allowing you to use Linux commands (Bash) as naturally as if they were built into Windows from the start.
In particular, the current mainstream version, WSL 2, runs a real Linux kernel internally, giving it extremely high compatibility and allowing almost all web development tools to run smoothly. The installation method we'll introduce will automatically set up this WSL 2, so you don't need to worry.
Step 1: The Super-Easy Way to Install WSL and Linux (Ubuntu)
The procedure used to be a bit complicated, but on modern versions of Windows 10 and Windows 11, installing WSL has become incredibly simple. All you need is a single command.
1-1. Open PowerShell as an "Administrator"
First, open "PowerShell" or "Terminal" with administrator privileges to run the command.
- Right-click on the Windows Start button.
- Select "Terminal (Admin)" or "Windows PowerShell (Admin)" from the menu.
- If a prompt appears asking, "Do you want to allow this app to make changes to your device?", click "Yes."
When a black or blue window appears, you're ready.
1-2. Run the Installation Command
Copy and paste the following command into the administrator PowerShell window you just opened, and press the Enter key.
wsl --install
This single command automatically performs all of the necessary steps for you:
- Enables the required WSL and Virtual Machine features.
- Downloads and installs the latest Linux kernel.
- Sets WSL 2 as the default.
- Downloads and installs a Linux distribution (Ubuntu by default).
Once the process is complete, you will be prompted to restart your computer. Follow the instructions to restart Windows.
Step 2: Initial Setup of Your Linux Environment
After Windows restarts, the Ubuntu setup process may begin automatically. If it doesn't, find and click on "Ubuntu" in the Start Menu. On the first launch, you will set up your user account for the Linux environment.
2-1. Create a Username and Password for Linux
When the terminal displays "Enter new UNIX username:", type the username you want to use in your Linux environment and press Enter (alphanumeric characters are recommended). This can be different from your Windows username.
Next, you will see "New password:". Type in your password. For security, the characters you type will not appear on the screen, but they are being entered correctly. When you're done, press Enter, and then re-enter the same password at the "Retype new password:" prompt and press Enter again.
If you see "Password: password updated successfully," your user has been created successfully. Your personal Linux environment is now ready.
2-2. Update Your Packages to the Latest Version
A freshly installed Linux might have slightly outdated software inside. Before you start using it, it's good practice to update the packages to the latest versions with the following commands. This is just like updating the OS on a new smartphone.
First, update the package list.
sudo apt update
If you are prompted for a password, enter the Linux password you just set.
Next, upgrade the installed packages.
sudo apt upgrade -y
With that, your Linux environment is now up-to-date and secure.
Step 3: Let's Use Bash on Windows!
Great work! All the preparations are now complete. You can launch Bash at any time by opening "Ubuntu" from the Start Menu. Let's confirm that the commands we learned in the previous article work just the same on your Windows machine.
Accessing Your Windows Files
A convenient feature of WSL is that you can easily access your Windows files from the Linux environment. Your Windows drives are "mounted" (connected) under the `/mnt/` directory. For example, your C: drive is `/mnt/c/`.
Let's take a look inside your Windows user folder. (Replace `YourWindowsUser` with your own Windows username).
$ ls -l /mnt/c/Users/YourWindowsUser/Documents
You should see a list of the contents of your Windows "Documents" folder. As you can see, WSL integrates seamlessly with Windows.
Creating a File in WSL
Of course, you can also create files within the Linux environment (such as in your home directory). Let's create a simple file to review what we learned last time.
$ echo "Hello from Bash on WSL!" > wsl_test.txt
Let's check the contents with the `cat` command.
$ cat wsl_test.txt
Hello from Bash on WSL!
Perfect! You are now freely wielding Bash on top of Windows.
Conclusion
In this article, we explained the most modern and powerful way for Windows users to get a Bash environment: installing WSL. You can install it with a single command, and once you launch it, you're in the world of Linux. We hope you were able to experience this ease and power for yourself.
With WSL, you can now use many of the command-line tools and development methods that once seemed exclusive to macOS and Linux users, right on your favorite Windows machine. This allows you to bring your development environment closer to your production server environment, enabling smoother and higher-quality web creation.
The image of the "scary black screen" is a thing of the past. From now on, we hope you'll master Bash as a reliable partner that makes your work more efficient.
Now that you can use Bash on Windows, our next topic is for macOS users. The default shell on recent versions of macOS has changed to Zsh, but for those who are thinking, "I still want to use Bash!", we'll explain how to switch to and make the most of Bash.