Working with the Terminal is a skill that we can develop when we work with programming. Installing an npm package, working with Git, or setting up a server, these are all tasks that we need to use the Terminal.
When we think about installing programs on the Windows Operating System, we usually think of installing through a graphical interface. However, last year Microsoft released a new program that gives us the option to install programs through the Terminal, a reality already present in Linux systems. We are referring to the Windows Package Manager, or winget, released in May 2020.
In this article, we will learn how to install this native Windows package manager and how we can use it to install, list, and remove programs.
Installing Winget
To use winget on our computer, it is necessary that we are using Windows 10 and that we have the “App Installer” application installed; it is available in the Microsoft Store.
We have two alternatives to access the latest features of this program.
We can be part of the Windows Insiders Program in general, thus gaining early access to any Windows news.
But it is also possible to download the Windows Package Manager installer from GitHub. Through this method, we can access the latest features added to this manager. Due to these advantages, we will use this method.
To access the link for the latest releases, click here.
On this page, we will click on the file with the .appxbundle extension:
When clicking on the downloaded file, just click the “Install” button and the installation will begin:
After a few seconds, Winget will be installed on our computer.
We can use winget through the Windows Terminal. So, let's open the Command Prompt application with Administrator permission. To do this, just right-click the application icon and then click More > Run as administrator:
To check if the installation was successful, we can type winget and press Enter. The following information should be displayed:
To know the installed version of winget, we can execute winget --version:
Installing Programs
To install programs, also called packages, we first need to find out if they are available through winget.
For that, we use the command winget search. Imagine, for example, that we want to install Git on our computer. To find out if it is available via winget, we can execute the command winget search git. A list of available packages will be returned:
Note that there are many packages that have “git” in their name. However, the Git we are looking for is the first in the list. Besides the package name, we need to pay attention to its ID, which is in the second column of the list. This information is very important for installing and uninstalling programs. In the case of Git, as we can see in the image above, the ID is “Git.Git”.
Thus, to install Git, we must execute winget install Git.Git.
Windows will begin the download and installation process for Git, even showing the installation windows:
At the end of the installation, we will see a confirmation message about the new package added to the Operating System:
To confirm that the installation occurred correctly, we can execute git --version:
Very interesting process, isn’t it?
Listing Programs
A new feature being tested in winget involves the ability to list the programs already installed, through the command winget list.
However, when using this new command, it is important to remember two things: 1) it is available only from version 0.3 11102 of winget; and 2) being currently an experimental feature, this command may undergo changes in the future.
To make use of this command, we need to enable it in the winget configuration file. We can open this file by executing winget settings:
The Windows will then open the settings.json file in your Operating System's default editor. If no default text editor is set, Notepad will be used.
You will need to add the experimentalFeatures key, indicating that the list command is enabled, via a boolean:
"experimentalFeatures": {
"list": true
}
After saving this file, we can return to the Terminal and execute winget list. Next, we will see a list of installed programs and their respective IDs, including the newly added Git:
// List of installed programs
Something interesting is that the Git ID is now “Git_is1”. This information will be necessary for the next operation we will perform.
Uninstalling Programs
The command to uninstall programs through winget is winget uninstall. This command is also experimental. Therefore, we also need to add it to the settings.json file, just as we did with the list:
"experimentalFeatures": {
"list": true,
"uninstall": true
}
To delete Git, we will need to inform its ID registered in winget. Thus, the uninstallation command will be as follows:
winget uninstall Git_is1
The Windows uninstallation window will be displayed:
At the end of this process, we will see the following message:
This message confirms that the removal of the Git package was successful.
Conclusion
With the commands presented in this article, we can manage our programs through the command line in Windows.
If you wish to follow the explanation in video format, see the #85 edition of our weekly program on YouTube, Hcode Café.
They can be applied to any program that we wish to install. We hope this article has helped you understand what the Windows Package Manager is and how to use it in your daily life, which can help you improve an increasingly necessary skill for all programmers: executing commands in the Terminal.
Until the next article! :)