Chocolatey

No, this article is not about my escapades with dessert. If you don’t already know Chocolatey is an awesome package manager made for Windows. The Windows operating system is sorely lacking in this regard where other operating systems arguably excel.

Linux has built in tools such as apt-get or pacman (and others depending on the distro) and MacOS has a third party package manager called Homebrew. Windows, unfortunately, has never had native package management. If you wanted to install something, you had to go to that software’s website, download an installer or some other sort of binary package and then manually install it. This gets really old if you have to repeatedly set up new computers with a given suite of software.

Why Have Package Managers?

Why should you even care about having a package manager? Package managers are great because they give you an easy way to not only install software, but also keep it up to date. Instead of manually checking for updates in all of the software you use, you can just run a command from your command line to the effect <package-manager> update -all.

This is great because it really limits how much time you waste keeping software up to date. As a software engineer, it’s important to keep my tooling as up to date as I can (to a reasonable degree depending on project needs), and I don’t want to spend my time going through multiple installers just to keep my build tools up to speed. This is where chocolatey comes in!

My Experience with Chocolatey

Overall, my experience with chocolatey has been great. I use it on all my machines at home and have had great success. They make it super easy to get started; just a single command that you execute in Powershell:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

or cmd.exe

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

And that’s it! You now have a package manager ready to go. To install packages you just run the choco command to search for and install packages.

This got me thinking…I could easily write powershell scripts to automate set-up of the machines I use. So I set out to write said scripts and after some Googling, here’s what I came up with for my C++ development workload:

# setup script I use for my development machines for C++
# This script will first install chocolatey and then 
# install a bunch of tools I use regularly. 
. "$PSScriptRoot\InstallChocolatey.ps1"
. "$PSScriptRoot\UpdateEnvironmentPath.ps1"

# install chocolatey
InstallChocolatey
Update-Environment-Path

## windows explorer settings ##
# Navigate registry
Push-Location
Set-Location HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced

# Show file extensions
Set-ItemProperty . HideFileExt "0"
# Show hidden files
Set-ItemProperty . Hidden "1"

Pop-Location

# Force Windows Explorer restart so settings take effect
Stop-Process -processName: Explorer -force

# install common dev tools
.\InstallCommonDevTools.ps1

choco install -y git --package-parameters="'/GitAndUnixToolsOnPath /WindowsTerminal'"
choco install cmake --yes
choco install LLVM --yes
choco install mingw --yes
choco install ninja --yes
choco install nsis --yes
choco install swig --yes
choco install sourcetree --yes

# visual studio
choco install VisualStudio2017Professional --yes
choco install visualstudio2017-workload-nativedesktop --yes
Write-Output "Finished! Run `choco upgrade all` to get the latest software"

You can run this script via PowerShell:

./developer-setup-cpp.ps1

And just like that, you have a C++ development environment ready to go! (Though you may want to update the Visual Studio installation version).

I also made another script to install development tools I use regularly:

. "$PSScriptRoot\InstallChocolatey.ps1"
. "$PSScriptRoot\UpdateEnvironmentPath.ps1"

# install chocolatey if not present
InstallChocolatey

# refresh environment path so choco command works
Update-Environment-Path

choco install RapidEE --yes
choco install dependencywalker --yes
choco install vscode --yes
choco install 7zip --yes
choco install miktex --yes
choco install beyondcompare --yes
choco install zeal --yes
choco install doxygen.install --yes
choco install sysinternals --yes

Similarly, you can run this script with:

./install-common-dev-tools.ps1

If you’re on Windows 10, one final script that I have found especially useful is the following one which was taken from Microsofts dev box setup repository. This script removes a lot of the unecessary apps that comes with Windows 10 out of the box.

# Taken from: https://github.com/Microsoft/windows-dev-box-setup-scripts/blob/master/scripts/RemoveDefaultApps.ps1
#--- Uninstall unecessary applications that come with Windows out of the box ---
Write-Host "Uninstall some applications that come with Windows out of the box" -ForegroundColor "Yellow"

#Referenced to build script
# https://docs.microsoft.com/en-us/windows/application-management/remove-provisioned-apps-during-update
# https://github.com/jayharris/dotfiles-windows/blob/master/windows.ps1#L157
# https://gist.github.com/jessfraz/7c319b046daa101a4aaef937a20ff41f
# https://gist.github.com/alirobe/7f3b34ad89a159e6daa1
# https://github.com/W4RH4WK/Debloat-Windows-10/blob/master/scripts/remove-default-apps.ps1

function removeApp {
	Param ([string]$appName)
	Write-Output "Trying to remove $appName"
	Get-AppxPackage $appName -AllUsers | Remove-AppxPackage
	Get-AppXProvisionedPackage -Online | Where DisplayNam -like $appName | Remove-AppxProvisionedPackage -Online
}

$applicationList = @(
	"Microsoft.BingFinance"
	"Microsoft.3DBuilder"
	"Microsoft.BingFinance"
	"Microsoft.BingNews"
	"Microsoft.BingSports"
	"Microsoft.BingWeather"
	"Microsoft.CommsPhone"
	"Microsoft.Getstarted"
	"Microsoft.WindowsMaps"
	"*MarchofEmpires*"
	"Microsoft.GetHelp"
	"Microsoft.Messaging"
	"*Minecraft*"
	"Microsoft.MicrosoftOfficeHub"
	"Microsoft.OneConnect"
	"Microsoft.WindowsPhone"
	"Microsoft.WindowsSoundRecorder"
	"*Solitaire*"
	"Microsoft.MicrosoftStickyNotes"
	"Microsoft.Office.Sway"
	"Microsoft.XboxApp"
	"Microsoft.XboxIdentityProvider"
	"Microsoft.ZuneMusic"
	"Microsoft.ZuneVideo"
	"Microsoft.NetworkSpeedTest"
	"Microsoft.FreshPaint"
	"Microsoft.Print3D"
	"*Autodesk*"
	"*BubbleWitch*"
    "king.com*"
    "G5*"
	"*Dell*"
	"*Facebook*"
	"*Keeper*"
	"*Netflix*"
	"*Twitter*"
	"*Plex*"
	"*.Duolingo-LearnLanguagesforFree"
	"*.EclipseManager"
	"ActiproSoftwareLLC.562882FEEB491" # Code Writer
	"*.AdobePhotoshopExpress"
);

foreach ($app in $applicationList) {
    removeApp $app
}

I highly encourage you to give chocolatey a try. It really made a lot of things easier for me when it comes to sofwtare installs and I’m even finding use for it at work where I routinely have to install/uninstall software from various computers for testing purposes. Having a package manager definitely makes things easier!

Leave a Comment

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

Loading...