Home » PowerShell » Install Package in PowerShell

Install Package in PowerShell

The `Install-Package` command is a PackageManagement cmdlet used to install one or more software packages on the local computer. This command installs a package from a package source. The package source can be a remote repository such as NuGet Gallery, local file, or network share.

The syntax for the install Package command is:

Install-Package
       [-Name] <String[]>
       [-RequiredVersion <String>]
       [-MinimumVersion <String>]
       [-MaximumVersion <String>]
       [-Source <String[]>]
       [-Credential <PSCredential>]
       [-Proxy <Uri>]
       [-ProxyCredential <PSCredential>]
       [-AllVersions]
       [-Force]
       [-ForceBootstrap]
       [-WhatIf]
       [-Confirm]
       [-ProviderName <String[]>]
       [<CommonParameters>]

Where:

  • Name is the name of the package to install.
  • Source is the name of the package source to use. The default will be used if you don’t specify the source.
  • ProviderName is the name of the package provider to use. The default provider will be used if you don’t specify a provider.
  • MinimumVersion is the minimum allowed package that you want to install.
  • MaximumVersion is the maximum allowed package that you want to install.
  • AllVersions – Install-Package install all available versions of the package.

In this article, we will discuss how to use the Install-Package command in PowerShell to install a package by package name.

How to Install a Package by Package Name

To install a package by package name, use the Install-Package command in PowerShell. This command takes the name of a package.

Install-Package Newtonsoft.Json

In the above PowerShell script, the Install-Package command installs the Nuget Package Newtonsoft.Json from the NuGet Gallery.

The output of the above script installs the latest version of the Newtonsoft.Json package from the NuGet Gallery.

How to Install a Specific Version of the Package

Use the Install-Package command in PowerShell to install a specific version of the package. You can provide either MinimumVersion or MaximumVersion of the package.

Install-Package Newtonsoft.Json -MinimumVersion 1.0.2 

In the above PowerShell script, the Install-Package command installs the Newtonsoft.Json package with the minimum version number 1.0.2 from the NuGet Gallery.

How to Install a Package from the Nupkg file

To install a package from the nupkg file stored on the local computer, use the Install-Package command along with the Source parameter to specify the local file.

Install-Package Newtonsoft.Json -Source C:\temp\file.nupkg

In the above PowerShell script, the Install-Package command installs the package Newtonsoft.Json from the local file C:\temp\file.nupkg

Conclusion

I hope the above article on how to use the Install-Package command in PowerShell to install a package on the local computer is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Related Links

PackageManagement

Get-Package

Find-Package

Get-PackageProvider

Install Nuget Package

Get-PackageSource

Register-PackageSource