How to Use Linux Terminal in Windows?

If you’re a fan of Linux’s power and flexibility, but you can’t completely leave the Windows environment behind, there’s good news. You can now access the Linux terminal in Windows 10, giving you a powerful tool at your fingertips. This fusion allows users to enjoy the best of both worlds, incorporating Linux’s flexibility into Windows’ user-friendly environment.

Linux Subsystem for Windows

Windows Subsystem for Linux (WSL) is a revolutionary feature that creates a lightweight environment for running the Linux terminal on Windows. It permits you to run Linux command-line utilities, including bash shells, test user-space apps, and even navigate through a file system, right from your Windows computer.

Let’s dig into what this feature has to offer:

  • A Compatibility Layer: WSL essentially acts as a compatibility layer. It’s designed to run Linux binary executables (in layman’s terms, programs) directly on Windows 10 and Windows Server 2019.
  • No Need for Virtual Machines: Unlike traditional methods that require setting up a resource-hungry virtual machine or a dual-boot setup, WSL operates by translating Linux system calls into Windows system calls. This means you can run Linux software straight from your Windows system, eliminating the need for a separate Linux interface.
  • Console Access: WSL provides a console window that serves as your playground for Linux. Here, you can choose your favorite Linux distribution, such as Ubuntu, Debian, or OpenSUSE, and run it on Windows.
  • Linux Commands on Windows: The console offers a command-line interface where you can perform typical Linux operations. Whether it’s running Linux commands, accessing your files, executing programming tasks, or even running graphical Linux applications with the help of an X server, WSL has you covered.

In essence, the Windows Subsystem for Linux creates a bridge between Linux and Windows platforms. It offers a seamless way for users to work across different operating systems within a single system, thereby enhancing productivity and efficiency.

How to Install Windows Subsystem for Linux (WSL)

The Windows Subsystem for Linux (WSL) is a tool that allows you to run Linux distributions on your Windows system without the need for a dual-boot setup or virtualization. This functionality is available in two versions – WSL1 and WSL2. In the following sections, we will guide you through the steps of installing WSL on your Windows system.

WSL1 vs. WSL2

Before we dive into the installation process, it’s crucial to understand the differences between WSL1 and WSL2:

  • WSL1: This is the original version of WSL, which implements a compatibility layer for running Linux binary executables natively on Windows.
  • WSL2: This is the latest version, which uses a highly optimized subset of a genuine Linux kernel, providing much better system performance and full system call compatibility.

The key difference between the two is the way that they handle system calls. WSL2, with its genuine Linux kernel, has improved performance and compatibility over WSL1.

System Requirements for WSL Installation

Before you can install WSL, there are a few system requirements that need to be met:

  1. You need to have a PC with Windows 10 installed. Specifically, for WSL2, you need to have version 1903 or higher.
  2. Your system architecture should be x86_64. WSL2 also supports ARM64 devices.
  3. For WSL2, you need to ensure that your system supports Hyper-V Virtualization.

Installing WSL on Windows

Now that we have a clear understanding of the requirements and differences between WSL1 and WSL2, let’s go through the installation process:

  1. Open PowerShell as an Administrator. You can do this by typing ‘PowerShell’ in the start menu, right-clicking on ‘Windows PowerShell,’ and selecting ‘Run as Administrator.’
  2. Enable the Windows Subsystem for Linux by typing in the following command and pressing Enter:
wsl --install
  1. Wait for your system to execute the command. It will automatically enable the necessary optional components, download and install the latest Linux kernel, set WSL2 as the default, and download a Linux distribution (Ubuntu by default).
  2. Once the installation is complete, the system will prompt you to restart your PC. Ensure that you save any ongoing work and then restart your PC.
  3. After restarting, you can open a new PowerShell window and type ‘wsl‘ to start using your new Linux subsystem. During the first launch, you’ll be asked to create a user account and password for your Linux distribution.
  4. If you want to switch between WSL1 and WSL2 or vice versa, you can do so by using the following command:
wsl --set-version <distribution-name> <versionNumber>

Just replace <distribution-name> with the name of your Linux distribution and <versionNumber> with ‘1‘ for WSL1 or ‘2‘ for WSL2.

With that, you have successfully installed the Windows Subsystem for Linux on your Windows system! You can now enjoy the flexibility of a Linux environment alongside your traditional Windows setup.

Choosing a Linux Distribution

Microsoft Store features several Linux distributions such as Ubuntu, Debian, OpenSUSE, among others. Ubuntu is commonly recommended for beginners due to its user-friendly interface and robust community support.

Ubuntu: The Jack-of-all-Trades

Ubuntu is one of the most popular Linux distributions out there, making it a perfect starting point for those new to Linux. It is well-documented, supported by a vast community of users, and comes with a rich software repository. Whether you’re developing software, managing databases, or even running a web server, Ubuntu’s extensive package list can cater to your needs. This Linux terminal on Windows provides a complete, Ubuntu-based environment packed with all the command-line utilities.

Debian: Stability and Versatility

Debian is another popular choice among Linux enthusiasts, known for its robustness and stability. If you prioritize a stable and secure environment, Debian might be the right choice for you. This Linux terminal for Windows maintains a vast collection of software and offers excellent support for different hardware architectures.

OpenSUSE: Enterprise-Grade Features

OpenSUSE is renowned for its enterprise-grade features. If you’re seeking a distribution that focuses on testing and rolling out solutions in an enterprise environment, you should consider OpenSUSE. It’s also worth noting that OpenSUSE places a high emphasis on security and scalability.

How to Install a Linux Distribution on Windows?

After you’ve enabled WSL and chosen your preferred Linux distribution, follow the steps below to install it:

  1. Open the Microsoft Store and search for your chosen Linux distribution (Ubuntu, Debian, OpenSUSE, etc.).
  2. Click on your chosen distribution and then click on the “Get” or “Install” button. The distribution will start downloading and installing.
  3. After the installation is complete, you can launch your newly installed Linux distribution either from the Start Menu or by typing the distribution’s name into the Windows terminal (for instance, “ubuntu” for Ubuntu, “debian” for Debian, or “opensuse” for OpenSUSE).
  4. During the first launch, the distribution will complete its setup and ask you to create a new user account and password.
  5. Once this setup is complete, you will be at the terminal prompt and can start using your new Linux environment.

Setting up the Linux Terminal

After installing your chosen Linux distribution, launch it from the Start menu. You’ll be prompted to create a user account and password during the first launch, which you will use to perform administrative tasks.

Launching the Linux Terminal

  1. To launch your Linux terminal for Windows, simply search for your installed Linux distribution in the Windows Start Menu (for instance, type “Ubuntu” if you’ve installed Ubuntu). Click on the application to open it.
  2. Alternatively, you can launch the Linux terminal from the Windows Terminal application. This newer app allows you to access multiple command lines like Command Prompt, PowerShell, and any installed Linux distributions in separate tabs.

Creating a User Account

During the initial launch of your Linux distribution, the terminal will prompt you to create a new user account. This account is separate from your Windows credentials and will have its set of permissions within the Linux environment.

  1. When asked for a username, type in your desired username and press Enter.
  2. The system will then ask you to create a password for this new account. Type in your preferred password and press Enter. You’ll need to confirm the password by typing it again when prompted.

Remember, the characters of the password won’t display as you type them in the Linux terminal for security reasons.

Setting Up Your Linux Environment

Now that you have created your user account and are logged into your Linux terminal on Windows 10, you can start setting up your environment. You might want to update the system, install new software, or modify the settings to suit your workflow.

  1. To update your system, use the command sudo apt update && sudo apt upgrade for Ubuntu and Debian, or sudo zypper update for OpenSUSE. The ‘sudo’ command runs the following command as an administrator.
  2. If you want to install new software, use the command sudo apt install [package_name] for Ubuntu and Debian, or sudo zypper install [package_name] for OpenSUSE. Replace ‘[package_name]’ with the name of the software you want to install.

Basic Linux Terminal Commands

Once set up, you can begin running commands. Here are some basic ones:

  • ls: Lists all files and directories in the current directory
  • cd: Changes the current directory
  • pwd: Displays the path of the current directory
  • touch: Creates a new file
  • rm: Removes a file

Managing Files and Directories

One of the biggest strengths of the Linux terminal is efficient file and directory management. You can create, navigate, modify, and delete files and directories swiftly and accurately using simple commands.

For instance, to create a directory, you would use the mkdir command, followed by the directory name. If you need to remove a directory, the rmdir command will do the job. To move or rename files, the mv command is your go-to. These commands, among others, make the Linux terminal a powerful tool for managing your system.

Installing Software Packages on Linux Subsystem

In the Linux world, you can use a package manager to install additional software. Each distribution has its package manager, for Ubuntu and Debian, it’s the Advanced Package Tool (‘apt‘). To install Python on your subsystem, you would run the command 'sudo apt install python3. This command will download and install Python and all its dependencies.

Accessing Windows Files from Linux Terminal

One of the many advantages of WSL is the ability to access your Windows files directly from the Linux terminal. Your C: drive, for example, is mounted under /mnt/c in the Linux subsystem. So, if you need to work on a file stored in your Windows system, you can easily navigate to it from the Linux terminal.

Updating and Maintaining the Linux Distribution

Just like any other system, keeping your Linux subsystem up to date is paramount. Regular updates ensure security, stability, and access to the latest features.

This is done by updating the repository lists and upgrading the software packages using 'sudo apt update && sudo apt upgrade'.

Uninstalling the Linux Subsystem

Should there be a need to uninstall the Linux subsystem, perhaps to free up system resources or due to a change in user requirements, it is as straightforward as its installation.

Uninstallation can be initiated from the “Apps and Features” settings in Windows 10. Locate your Linux distribution and click the “Uninstall” button. This action removes the distribution along with any modifications, new applications, and user settings.

Frequently Asked Questions

Can I install multiple Linux distributions?

Yes, you can install multiple Linux distributions and switch between them.

Is it safe to access Windows files from Linux terminal?

Yes, but be careful when modifying system files as it could impact your Windows installation.

Can I use Linux GUI applications with WSL?

With WSL2 and Windows 10 updates, it’s now possible to run some Linux GUI applications.

How do I update the Linux kernel in WSL2?

Microsoft provides updates to the Linux kernel through Windows Update, so just keeping your PC updated will keep the Linux kernel updated as well.

Can I run Windows commands from the Linux terminal?

Yes, you can call Windows commands from the Linux terminal by using cmd.exe /C command.

Conclusion

Using a Linux terminal in Windows broadens your scope, opening up a world of command line utilities. Thanks to WSL, managing Linux commands on a Windows 10 system has never been easier. Whether you’re a developer, a system admin, or a curious user wanting to explore Linux, the seamless integration of the Linux terminal on Windows can significantly enhance your productivity.

Share your love
cult.technology
cult.technology
Articles: 204

Leave a Reply

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