PowerShell, developed by Microsoft, is a robust scripting language and automation framework that has carved a niche among Windows administrators. However, its capabilities aren’t confined to Windows alone. Recognizing the growing demand for cross-platform solutions, Microsoft expanded PowerShell’s reach to Linux, including distributions like Ubuntu.
Additional features of PowerShell:
- Cross-Platform Efficiency: PowerShell’s compatibility with Windows, macOS, and Linux ensures a consistent experience, enabling users to deploy the same scripts and commands across diverse operating systems.
- Advanced Automation: Renowned for its automation prowess, PowerShell facilitates the crafting of intricate scripts for task automation, system management, and efficient data processing.
- Seamless Microsoft Integration: For those engaged with Microsoft platforms like Azure, Office 365, or Active Directory, PowerShell offers tailored cmdlets and modules, streamlining interactions.
- Vibrant Community Backing: A dynamic and expansive PowerShell community offers invaluable resources, from specialized modules to expert guidance, enhancing user efficiency.
- Ongoing Development: Microsoft’s commitment to PowerShell’s evolution ensures it remains at the forefront of technological advancements.
For those keen on harnessing PowerShell’s capabilities on Ubuntu, we will continue the installation process using Microsoft’s official APT repository, ensuring you can access the latest versions and updates.
Prerequisites for Installing PowerShell
To successfully install PowerShell on Ubuntu, ensure you meet the following requirements:
System Requirements and Supported Ubuntu Versions
Component | Minimum Requirement |
---|---|
Processor | 2 GHz or faster dual-core processor |
RAM | 4 GB or more |
Disk Space | 25 GB of free space |
Network | High-speed internet connection |
Supported Versions | Ubuntu 22.04 (Jammy), Ubuntu 20.04 (Focal) |
Additional Requirements
Most of these will be automatically available on your default Ubuntu installation.
Requirement | Description |
---|---|
Internet Connection | Necessary for downloading PowerShell and applying updates. |
Terminal Conventions | All terminal commands should be executed as a regular user with sudo privileges. |
CLI Commands | Utilize the Command Line Interface (CLI) for installation and setup. |
Package Management Tools | Ensure tools for managing packages are installed (e.g., apt , dpkg ). |
Update Ubuntu Before PowerShell Installation
Before installing, update your system to ensure all packages are up-to-date. This helps avoid any conflicts during the installation. To do this, open a terminal and execute the following command:
sudo apt update
Once the update is complete, upgrade any outdated packages with the command below:
sudo apt upgrade
Install Initial PowerShell Packages
To install PowerShell, you need to have specific dependencies in place. While most of these packages might already be present on your system, executing the following command ensures they are installed:
sudo apt install dirmngr lsb-release ca-certificates software-properties-common apt-transport-https curl -y
Import Microsoft PowerShell APT Repository
To ensure you always have the most up-to-date version of PowerShell available on your system, you must import the GPG key and the repository. Start by importing the GPG key using the command:
curl -fSsL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor | sudo tee /usr/share/keyrings/powershell.gpg > /dev/null
Next, import the repository that matches your Ubuntu distribution version.
Note: Ubuntu 24.04 Noble Numbat LTS is not supported at this time.
For Ubuntu 22.04 Jammy JellyFish LTS users, execute the following command:
echo "deb [arch=amd64,armhf,arm64 signed-by=/usr/share/keyrings/powershell.gpg] https://packages.microsoft.com/ubuntu/22.04/prod/ jammy main" | sudo tee /etc/apt/sources.list.d/powershell.list
For Ubuntu 20.04 Focal Fossa LTS users, execute this command:
echo "deb [arch=amd64,armhf,arm64 signed-by=/usr/share/keyrings/powershell.gpg] https://packages.microsoft.com/ubuntu/20.04/prod/ focal main" | sudo tee /etc/apt/sources.list.d/powershell.list
Update the Packages List After the PowerShell PPA Import
After adding the PowerShell repository, update the packages list by running the following command:
sudo apt update
Finalize PowerShell Installation via APT Command
With everything in place, you can now install PowerShell using the command below:
sudo apt install powershell
Verify PowerShell Installation
With the installation complete, verifying that PowerShell has been correctly installed and is functional on your Ubuntu system is essential. To activate and launch a new PowerShell instance, enter the following command in your terminal:
pwsh
Upon executing the command, you should see a new PowerShell prompt, indicating that it runs successfully on your system.
Now that you have confirmed the successful installation of PowerShell, you can use it to manage your system, run scripts, and execute commands just like you would on a Windows system.
Basic PowerShell Commands
Accessing Help with PowerShell
To access the built-in help system and learn more about PowerShell commands and their usage, use the help
command:
help
This command provides an overview of available cmdlets and basic usage instructions.
Obtain PowerShell Information
To get detailed information about the PowerShell environment, such as version and runtime, use the Get-Host
cmdlet:
Get-Host
List Directory Contents on PowerShell
To list the contents of a directory, similar to the ls
command in Linux, use the dir
alias for the Get-ChildItem
cmdlet:
dir
Display Command History on PowerShell
To view the history of previously executed commands in the current PowerShell session, use the Get-History
cmdlet:
Get-History
List Process Information on PowerShell
To display information about the processes running on your system, use the Get-Process
cmdlet:
Get-Process
Exit PowerShell instance on PowerShell
exit
Additional PowerShell Commands
Update PowerShell
To check for updates and upgrade all packages, including PowerShell, use the command line and execute the following command. This command ensures your system stays up-to-date:
sudo apt update && sudo apt upgrade
Remove PowerShell
If you decide to remove PowerShell from your system, follow these steps:
Use the following command to uninstall PowerShell:
sudo apt remove powershell
Remove the repository by executing the following command:
sudo rm /etc/apt/sources.list.d/powershell.list
For good housekeeping and security, delete the GPG key using the following command:
sudo rm /usr/share/keyrings/powershell.gpg
Conclusion
In conclusion, installing PowerShell on Ubuntu using Microsoft’s official APT repository provides users with a powerful and versatile command-line interface. Following the steps outlined in this guide, users can seamlessly integrate PowerShell into their Ubuntu environment, expanding their toolkit for efficient system management.
Useful Links
Here is a valuable link related to using PowerShell:
- PowerShell Documentation: Access comprehensive documentation, including tutorials and reference materials, for detailed guides on installing, configuring, and using PowerShell.