How can I upgrade a Chocolatey package if it's already installed, and install it if it isn't?

I'm writing a set of PS scripts to help set up and maintain a Windows dev environment. Right now, I am maintaining two script files, one for installing Chocolatey packages, and another for upgrading the same packages.

The two scripts are very straightforward, they look more or less like this:

# choco-install.ps1
choco install git
choco install VisualStudioCode
# ...
# choco-upgrade.ps1
choco upgrade git
choco upgrade VisualStudioCode
# ...

I'd like to merge these into a single script that, for each package, will install it if it's not installed, and upgrade the package if it is installed already. I'd like to be able to share these scripts, therefore they must not interfere with other Chocolatey packages that a user might have installed.

Is there a built-in chocolatey command to accomplish this, or another powershell trick I could use?

1

1 Answer

Running choco upgrade will install the package if it isn't already installed.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like