Install Package - PowerShell
Overview
Install-Package is a versatile PowerShell command that simplifies the installation of NuGet packages for PowerShell modules. It empowers users to swiftly add or update pre-built reusable libraries, tools, and utilities in their PowerShell scripts.
Syntax
Install-Package [-Name] <string[]> [-Source] <string> [-Version] <Version> [-IncludeDependencies] -SkipDependencies] [-Path] <string> [-Force] [-AllowClobber] [-AllowPrerelease] [-OutputFile] <string> [-Preview] [-Parameter] <string[]> [-ThrottleLimit] <int> [-UserAgent] <string> [-Debug] [-ErrorAction] <ActionPreference> [-ErrorVariable] <string> [-OutVariable] <string> [-OutBuffer] <int> [-Verbose] [-WarningAction] <ActionPreference> [-WarningVariable] <string> [-WhatIf]
Options/Flags
- -Name: Specifies the name of the package to be installed.
- -Source: Defines the NuGet source from which to install the package.
- -Version: Specifies the version of the package to be installed.
- -IncludeDependencies: Indicates whether the command should install dependencies of the specified package.
- -SkipDependencies: Indicates whether the command should skip installing dependencies of the specified package.
- -Path: Specifies the installation path for the package.
- -Force: Overwrites existing files during the installation process.
- -AllowClobber: Allows existing files to be overwritten during the installation process.
- -AllowPrerelease: Permits the installation of prerelease versions of packages.
- -OutputFile: Generates a log file containing detailed information about the installation process.
- -Preview: Displays a preview of the installation details without actually performing the installation.
- -Parameter: Specifies additional parameters for the package installation.
- -ThrottleLimit: Sets the maximum number of concurrent connections to the NuGet source.
- -UserAgent: Customizes the user agent string used by the command.
- -Debug: Enables debug mode, generating verbose output for troubleshooting.
- -ErrorAction: Specifies the action to take in case of an error during the installation.
- -ErrorVariable: Stores error information in a specified variable.
- -OutVariable: Assigns the command output to a specified variable.
- -OutBuffer: Sets the maximum number of items to store in the output buffer.
- -Verbose: Enables verbose output, displaying detailed progress information.
- -WarningAction: Specifies the action to take in case of a warning during the installation.
- -WarningVariable: Stores warning information in a specified variable.
- -WhatIf: Simulates the installation process without making any changes.
Examples
Simple Installation:
Install-Package PowerShellGet
Installing a Specific Version:
Install-Package PSReadLine -Version 2.1.0
Installing from a Specific Source:
Install-Package MyModule -Source https://myget.org/F/my-feed/
Skipping Dependencies:
Install-Package MyModule -SkipDependencies
Common Issues
- Package Not Found: Ensure the package name is correct and exists in the specified NuGet source.
- Missing Administrative Privileges: Administrator privileges are often required for installation.
- Dependency Resolution Issues: If dependency resolution fails, try updating the NuGet package source.
- Network Connectivity Problems: Check your internet connection and ensure you can reach the NuGet source.
Integration
Combined with Install-Module: Install-Package can be used to install PowerShell modules that are available as NuGet packages.
Example:
Install-Module -Name SomeModule -RequiredVersion 2.0.0
Install-Package -Name SomeModule.Dependencies