Chocolatey: The Easiest Way to Install and Manage Windows Software

Repro Dev - Feb 18 - - Dev Community

Working on Windows has it’s advantages when it comes to software and installing with most programs having a Windows Version available for download every time.

Sometimes that sponsored Google Search link you just clicked is actually the wrong software or worse yet, a malicious malware version of it.

On Linux, you can use an inbuilt package manager like Apt in Ubuntu to download the latest version from a trusted centralised source. You can install and update it using just the command line.

That’s where the Chocolatey package manager can help to give you that Linux experience on Windows with a tastier way to do things.


In this guide and overview, we’ll be installing Chocolatey using Windows PowerShell on Windows 11 to start installing our first packages.

We’ll be looking at

  • What is Chocolatey?
  • Install Chocolatey using Windows PowerShell
  • Where and how to search for packages?
  • Install our first package (Google Chrome)
  • Upgrade our first package
  • Uninstall our first package
  • Install several packages at once (Google Chrome, Notepad++ and 7zip)
  • Upgrade several packages at once (Google Chrome, Notepad++ and 7zip)
  • Upgrade all packages installed by Chocolatey
  • Uninstall all packages installed by Chocolatey
  • Check the packages currently installed by Chocolatey
  • Uninstall and remove Chocolatey
  • What about Winget?
  • Chocolate for Automated Windows Virtual Machine Deployment and Configuration

What is Chocolatey?

Chocolatey is a package manager for Windows, that once installed, lets you download and install programs in just a few words using only the command line without you having to do much else.

Instead of having to open a browser and go to the website to download a program like Google Chrome and going through the whole setup process manually, Chocolatey can automate this.

Programs are called packages in Chocolatey and you’ll find most programs have a package in the community repository. Some of these being maintained by the developers themselves and are verified to be the latest working versions.


Install Chocolatey on Windows

The install for Chocolatey is similar to the installation of any other package and is done by using a one line command in Windows PowerShell.
Chocolatey.org Install Link

  • Open Windows Powershell and “Run as administrator

  • Copy the one line command for the Chocolatey installation script below
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Enter fullscreen mode Exit fullscreen mode

  • Once it completes it will bring you back to the Powershell Command Line
  • Type the choco command below to check the install is working, call the program and print the current version

choco

Congratulations, you’ve now installed the Chocolatey package manager and can start managing packages using the command line on Windows.


Where and How to search for packages?

Chocolatey is a useful tool because of the large number of packages in its repository.

There is one for nearly every piece of software you can think of and you’ll usually be able to find it quite quickly.

You can search for the package you need by either using the command line or if that doesn't work, by searching on their website repository in a browser.


Searching for packages using the command line

We’re going to search for 7zip and we'll be using that later on in the guide

  • Open a Windows PowerShell terminal and “Run as administrator”

  • Type the below command to search the repository for 7zip

choco search 7zip

  • This will bring a list of search results for the program and if you scroll back up to the top you’ll find it’s usually the first result with a version number after it.

  • These will also have notes in the right hand side telling you if they are approved, broken or have been replaced by a new package.
  • We can scroll back up the list to see the whole list of packages.
  • In our case, the first hit is 7zip so that’s going to be the name of the package we would need to use with Chocolatey.

We'll go over the other way to search for these when we Install our first package, Google Chrome.


Install our first package (Google Chrome)

For our first package we’re going to use is for a piece of software most people will install as part of Windows initial boot up. We’re going to install the Google Chrome browser.

We’re going to start by getting the correct package name for Google Chrome so we can get it installed

  • Let’s search for Google Chrome in the repository using the search command

choco search chrome

  • This brings up 169 packages to choose from.
  • Scrolling up to the top and it doesn’t look like any of these are the correct one so instead we’ll check on the Community Repository page.

  • Open a web browser and go to the Community Repository

  • If we scroll down we can see this as one of the top 5 hits on the page and it’s actually listed as googlechrome

  • We can find this from a search by using that name

  • Click to get through to the individual project page for this application
  • This page will give you more information on our package for Google Chrome, the last time it was updated and the code we need to paste into our terminal.

  • Go back to your Powershell Terminal to paste the command from this page
  • Run the below command to start the installation

choco install googlechrome

  • It will now start the download of Google Chrome but will stop asking if you are sure you want to complete the installation

  • To confirm the install and run the script you need to type y

  • Close your Powershell Terminal to exit or press Ctrl+C to cancel as we're going to do something different

Automating the Single Package install

  • As we want to automate this further then we’re going add one more thing to the choco command
  • Adding the -y switch to the end will say y automatically to as many of the prompts as it can for you
  • Open a new Powershell window as Administrator so we can try this again
  • Type in the below command and Press Enter

choco install googlechrome -y

  • Time to grab a cup of coffee while Chocolatey does it’s thing

  • Once it's finished the install script you can go ahead and find that we've automatically got a Desktop Shortcut to Google Chrome added

  • It's all been added to our Start Menu

  • Opening it up for the first time we're greeted with the normal first time run for Google Chrome with no noticeable or functional difference to a regular install.

Congratulations, you’ve now installed your first package using Chocolatey. Next up, even though we’ve just installed it let’s look at how to upgrade it.


Upgrade our first package

In most cases you won’t have to upgrade any of your packages manually using Chocolatey as they will tend to update as normal in most cases when you open them up.

  • To upgrade Google Chrome manually using Chocolatey we can use the below command

choco upgrade googlechrome

  • Add the -y switch to automate this further

choco upgrade googlechrome -y

This will download the latest version from the Community Repository and upgrade the program if there’s one available.

I would suggest that you close up the program when you do this or it may fail when you try.


Uninstall our first package

Just like installing programs, uninstalling programs can be quite the long process on Windows and here Chocolatey can automate the process for you again.

We're going to Uninstall Google Chrome from this machine.

  • To uninstall Google Chrome using Chocolatey we can use the below command

choco uninstall googlechrome -y

  • This will uninstall the package in most cases without you having to do anything else.

There is a chance with some applications that the uninstall from here won't fully remove the files. For example, there still be there may be a Programs File Folder with your user data. If this happens you’ll be prompted to use the actual program's uninstall program. You may have to then manually delete those folders if needed for a full clean uninstallation.

Congratulations, we’ve now covered the basics of Chocolatey and you’ve managed one package but it’s time to start managing multiple packages at once.


Install several packages at once (Google Chrome, Notepad++ and 7zip)

Installing one program at a time, using choco commands is quite useful but we can use those same commands to manage more than just one package.

We’ll be installing Google Chrome, Notepad++ and 7zip all in one go using just one line of code.

We’ve already seen how we can get the package names from the repository so we’re going to skip ahead to the install.

We can add as many of the package names after each other to chain the install command and add the -y switch at the end of it to press y throughout the installation to make it unattended.

  • Open up a new Windows PowerShell terminal and “Run as administrator”

  • Run the below command to start the installation

choco install googlechrome notepadplusplus 7zip -y

  • This will take 5 to 10 minutes and is definitely time to go and grab a coffee as Chocolatey gets to work on the download and install of the programs

If we take a look on our Desktop we now have the Google Chrome shortcut and in our Start Menu as we normally would.

  • We can also see 7zip has installed with shortcuts in the Start Menu

  • Google Chrome is in the Start Menu

  • Finally we can see that Notepad++ has also been installed as normal and can be found in the Start Menu aswell

Congratulations, you just downloaded and installed 3 programs at once using just one line of code and Chocolatey. The best part was it did this unattended so you could do something else thanks to good old fashioned automation.


Upgrade several packages at once (Google Chrome, Notepad++ and 7zip)

When you're working with more than one package and need to upgrade just a few you can use the same principle and name the packages you want to upgrade.

Use the below command to upgrade the packages we just installed only

choco upgrade googlechrome notepadplusplus 7zip -y

This will search out any upgrades and apply them if needed all at once.


Uninstall several packages at once (Google Chrome, Notepad++ and 7zip)

Just like the Uninstall Choco command for one package you can uninstall as many packages as you want by adding the package names to the command.

Please Note: You may need to input some commands when using the uninstall choco command as not all of it can be automated. In those rare cases like in this example below you’ll have to wait to see if you’re prompted and follow the instructions in the terminal

  • Open a Powershell window using "Run as Administrator"
  • Run the below command

choco uninstall googlechrome notepadplusplus 7zip -y

  • In this case, Notepad++ has another service called a metapackage that’s been installed to help run it.
  • Chocolatey will ask if we want to uninstall that Notepadplusplus.service too.
  • We only have 20 seconds for each answer before it fails so type Y and Press Enter twice to start the uninstallation of NotePad++ and continue.

  • In this example, 7zip has a metapackage as well so we'll have to type Y and Press Enter twice to uninstall 7zip and continue.

  • Google Chrome can be uninstalled without any further intervention so will start to uninstall it's self now

  • This should take about 5 minutes to fully complete and in this example you won't be prompted again but watch out for those packages that do.

  • We’ve now uninstalled all of the packages and we should have a list of the main packages not the metapackages we removed
  • If we go to our Start Menu all of our installed programs have now been removed


Check current installed packages

We can check the packages currently installed by Chocolatey by using the below command

choco install


Upgrade all packages

Use at your own risk and make sure you're not in the middle of something important if you decide to run the below command.

It'll upgrade every package you've currently got installed without any confirmation which can be useful but not the best way of doing this.

choco upgrade all -y


Uninstall Chocolatey and All Packages

We’ve had a lot of fun playing around with Chocolatey and installing packages from the command line but what if you want to just to go back to the way it was.

Well, we can use the choco uninstall command to remove Chocolatey and most of the software it installed for us

Beware: Be absolutely sure you want to remove all the packages you’ve installed up till now. Once you’ve hit Enter after typing in this command you won’t be able to interrupt it without causing issues to some of the programs and your overall Windows installation.

choco uninstall all

You can use the -y switch if you are sure that you don’t want to be prompted per package. Remember that some packages will still require you to press Yes so you may want to stick around for this mass uninstall.

choco uninstall all -y


What about Winget?

Winget was introduced as the package manager by Microsoft for Windows 10 upwards in 2021.

Use the winget tool to install and manage applications

It does what Chocolatey does but relies on the Microsoft Store for it’s repository of packages and programs.

As it uses the Microsoft Store, it currently has not as many packages to choose from as Chocolatey does. This does seem to be the future plan from

You’ll find that right now the package you want won’t be available using Winget but will be when using Chocolatey.

It's useful in it’s current state but needs a little time to mature and for more packages to be added to the Microsoft store.

When this happens, it will be a major competitor to the long standing dominance of Chocolatey in the Windows package management space.

For me though Chocolatey still wins out.


Chocolatey for Automated Windows VM Configs

Overall, I’m a big fan of Chocolatey and using one line to automate the installation of my most useful apps makes my life much simpler for Windows Virtual machines especially.

We’re going to look at a few bigger use cases in a future guide when we look at using it as part of the automated setup and deployment of a Windows 11 Virtual Machine running on Esxi 8.0.

There's a lot more inspiration that you can find in the Chocolatey subreddit too

https://www.reddit.com/r/chocolatey/


Congratulations for getting through this overview and guide to Chocolatey. It wasn't the shortest blog so well done for making it to the end.

I hope I've given you a few ideas of what you can do with this and how it might save you a lot of time on some of the boring system admin you have to do.


Don't forget to explore the rest of our website as we build out more content. Stay tuned for more tutorials, tips, and tricks to help you make tech work for you.

If you want to stay up-to-date with regular updates, make sure to subscribe to our free mailing list.


. . . . . . . . . . . . .