How to install PowerShell on Linux 8

Share on Social Media

Learn how to install PowerShell on Linux with this comprehensive guide. Follow easy, step-by-step instructions to set up and start using PowerShell on your Rocky Linux 8 system. #centlinux #linux #powershell

What is PowerShell?

PowerShell is a cross-platform task automation and configuration management framework, consisting of a command-line shell and scripting language. Developed by Microsoft, it is designed to automate system tasks, manage system configurations, and perform administrative tasks. PowerShell is built on the .NET framework, providing a robust environment for system administrators and power users.

Key features of PowerShell include:

  1. Cmdlets: Specialized commands that perform specific operations, such as file manipulation, system management, and network configuration.
  2. Pipelines: Allowing the output of one cmdlet to be used as input for another, enabling complex task automation.
  3. Scripting Language: A powerful, flexible scripting language that supports complex logic, error handling, and more.
  4. Remote Management: Enabling administrators to manage multiple systems remotely.
  5. Cross-Platform: Available on Windows, macOS, and Linux, making it a versatile tool for diverse environments.

PowerShell enhances productivity by enabling the automation of repetitive tasks, simplifying the management of system configurations, and providing a unified management interface across different operating systems.

Read Also: How to install SQL Server on CentOS 7

Install PowerShell on Linux 8
Install PowerShell on Linux 8

What is PowerShell used for?

PowerShell is used for a wide range of tasks in system administration, automation, and configuration management. Here are some of its primary uses:

  1. Automating System Tasks: PowerShell automates repetitive tasks such as file management, system updates, and user account management, saving time and reducing the potential for human error.
  2. Configuration Management: PowerShell is used to configure and manage systems. Administrators can script the setup and configuration of servers, networks, and applications to ensure consistent and repeatable deployments.
  3. System Administration: PowerShell provides administrators with powerful tools to manage local and remote systems, including managing services, processes, and system settings.
  4. Scripting and Automation: The scripting capabilities of PowerShell allow users to write scripts to automate complex workflows and administrative tasks. These scripts can handle conditional logic, loops, and error handling, making them robust solutions for task automation.
  5. Managing Windows and Linux Systems: PowerShell can be used to manage both Windows and Linux systems, offering a unified command-line interface for cross-platform administration.
  6. Interacting with APIs: PowerShell can be used to interact with web APIs, allowing for automation of cloud services, application deployment, and other tasks that involve web-based interfaces.
  7. Data Processing: PowerShell can process data from various sources, including files, databases, and web services. It can manipulate and transform data, making it useful for data analysis and reporting.
  8. Remote Management: With PowerShell Remoting, administrators can manage multiple remote systems from a single interface, executing commands and scripts across multiple machines simultaneously.
  9. DevOps and CI/CD: PowerShell is widely used in DevOps practices and Continuous Integration/Continuous Deployment (CI/CD) pipelines to automate the deployment and management of applications and infrastructure.

By leveraging these capabilities, PowerShell helps streamline administrative tasks, improve efficiency, and ensure consistency across IT environments.

Recommended Training: Linux Administration: The Complete Linux Bootcamp in 2025 from Andrei Dumitrescu, Crystal Mind Academy

3371848 9ea9 18

Update Linux Operating System

Using an SSH client, establish a secure connection to the Rocky Linux server (rockylinux-01.centlinux.com) as the root user. This step provides you with administrative privileges, allowing you to perform system-wide configurations and software installations. It’s essential to use the root account or a user with sudo access to ensure you have the necessary permissions for the setup process.

Once connected, the next step is to build the cache for the installed YUM repositories. Building the cache ensures that the YUM package manager has the latest metadata about the repositories and their available packages. This process reduces the time required for package searches, updates, and installations, ensuring smooth and efficient operations. To proceed, execute the appropriate command to refresh the YUM repositories and populate the cache with up-to-date data.

# dnf makecache
Rocky Linux 8 - AppStream                       1.3 kB/s | 4.8 kB     00:03
Rocky Linux 8 - BaseOS                          1.2 kB/s | 4.3 kB     00:03
Rocky Linux 8 - Extras                          1.0 kB/s | 3.1 kB     00:03
Metadata cache created.

Execute following command to update software packages that are already installed on your Rocky Linux operating system.

# dnf update -y
Last metadata expiration check: 0:01:01 ago on Mon 23 May 2022 07:13:55 PM PKT.
Dependencies resolved.
Nothing to do.
Complete!

Our Linux server is already up-to-date. So, there is has nothing to update. But the output may vary on your Linux server.

After updating your Linux server, Check the versions of your operating system and Linux Kernel as follows.

# cat /etc/rocky-release && uname -r
Rocky Linux release 8.6 (Green Obsidian)
4.18.0-372.9.1.el8.x86_64

Install PowerShell on Linux

The first step in preparing your Rocky Linux system for installing Microsoft PowerShell is to import the GPG key for the official Microsoft YUM repository. This GPG key is crucial for verifying the authenticity and integrity of the packages downloaded from the repository. Without it, the system cannot confirm that the packages are legitimate and untampered. By importing the GPG key, you ensure that your system only installs trusted software directly from Microsoft’s official sources.

To import the GPG key, you will use the rpm command, which is the standard tool for managing RPM-based packages on Rocky Linux. Executing this command will securely add the key to your system’s keyring, allowing you to proceed with confidence in the repository’s security and reliability. This step lays the foundation for a smooth and secure installation process.

# rpm --import https://packages.microsoft.com/keys/microsoft.asc

Download and install Microsoft Official yum repository on your Rocky Linux server.

# dnf install -y https://packages.microsoft.com/config/rhel/8/packages-microsoft-prod.rpm
Last metadata expiration check: 0:08:20 ago on Mon 23 May 2022 07:13:55 PM PKT.
packages-microsoft-prod.rpm                     7.7 kB/s | 6.8 kB     00:00
Dependencies resolved.
================================================================================
 Package                      Arch        Version       Repository         Size
================================================================================
Installing:
 packages-microsoft-prod      noarch      1.0-1         @commandline      6.8 k

Transaction Summary
================================================================================
Install  1 Package

Total size: 6.8 k
Installed size: 204
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : packages-microsoft-prod-1.0-1.noarch                   1/1
  Verifying        : packages-microsoft-prod-1.0-1.noarch                   1/1

Installed:
  packages-microsoft-prod-1.0-1.noarch

Complete!

Rebuild cache for newly installed yum repositories.

# dnf makecache
Rocky Linux 8 - AppStream                       1.2 kB/s | 4.8 kB     00:04
Rocky Linux 8 - BaseOS                          1.6 kB/s | 4.3 kB     00:02
Rocky Linux 8 - Extras                          1.2 kB/s | 3.1 kB     00:02
packages-microsoft-com-prod                     745 kB/s | 3.4 MB     00:04
Metadata cache created.

List down the available powershell packages as follows.

# dnf search powershell
Last metadata expiration check: 0:00:47 ago on Mon 23 May 2022 07:24:11 PM PKT.
====================== Name & Summary Matched: powershell ======================
powershell.x86_64 : PowerShell is an automation and configuration management
                  : platform.
powershell-lts.x86_64 : PowerShell is an automation and configuration management
                      : platform.
powershell-preview.x86_64 : PowerShell is an automation and configuration
                          : management platform.

                          : management platform.

By using dnf command, install PowerShell on Linux server.

# dnf install -y powershell
Last metadata expiration check: 0:01:13 ago on Mon 23 May 2022 07:24:11 PM PKT.
Dependencies resolved.
================================================================================
 Package       Arch      Version           Repository                      Size
================================================================================
Installing:
 powershell    x86_64    7.2.4-1.rh        packages-microsoft-com-prod     66 M
Installing dependencies:
 libicu        x86_64    60.3-2.el8_1      baseos                         8.8 M

Transaction Summary
================================================================================
Install  2 Packages

Total download size: 74 M
Installed size: 213 M
Downloading Packages:
(1/2): libicu-60.3-2.el8_1.x86_64.rpm           312 kB/s | 8.8 MB     00:28
(2/2): powershell-7.2.4-1.rh.x86_64.rpm         878 kB/s |  66 MB     01:16
--------------------------------------------------------------------------------
Total                                           975 kB/s |  74 MB     01:18
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : libicu-60.3-2.el8_1.x86_64                             1/2
  Running scriptlet: libicu-60.3-2.el8_1.x86_64                             1/2
  Installing       : powershell-7.2.4-1.rh.x86_64                           2/2
  Running scriptlet: powershell-7.2.4-1.rh.x86_64                           2/2
  Verifying        : libicu-60.3-2.el8_1.x86_64                             1/2
  Verifying        : powershell-7.2.4-1.rh.x86_64                           2/2

Installed:
  libicu-60.3-2.el8_1.x86_64            powershell-7.2.4-1.rh.x86_64

Complete!

To verify installation of Windows PowerShell, execute following command at Linux bash prompt to check the version of installed pwsh command.

# pwsh -v
PowerShell 7.2.4

Windows PowerShell is successfully installed on your Linux server.

Execute PowerShell Commands in Rocky Linux 8

To start using PowerShell on your Rocky Linux system, execute the pwsh command in the terminal. This command launches the PowerShell interactive shell, providing access to its robust scripting environment and a wide range of cmdlets for system administration and automation. Once inside the PowerShell environment, you can begin testing its functionality by executing some basic commands. For example, you can try retrieving system information using Get-Host, listing processes with Get-Process, or exploring available cmdlets with Get-Command.

Running these test commands not only confirms that PowerShell has been installed correctly but also allows you to familiarize yourself with its capabilities and syntax. As PowerShell is cross-platform, its commands and scripts work similarly across Windows, Linux, and macOS, ensuring consistency in your workflow. This step marks the beginning of leveraging PowerShell’s powerful features to streamline system management and scripting tasks.

# pwsh
PowerShell 7.2.4
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /root> Get-Date

Monday, May 23, 2022 7:31:14 PM

PS /root> Get-PSDrive

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
/                   2.49         35.73 FileSystem    /
Alias                                  Alias
Env                                    Environment
Function                               Function
Temp                2.49         35.73 FileSystem    /tmp/
Variable                               Variable

PS /root> exit

Read Also: Mastering Shell Scripting in Linux

Final Thoughts

Installing PowerShell on Rocky Linux 8 provides a versatile and cross-platform scripting environment for automating tasks and managing systems effectively. By following the installation steps—updating the system, adding the Microsoft repository, importing the GPG key, and installing PowerShell—you can seamlessly integrate this powerful tool into your Linux environment.

PowerShell on Linux offers administrators and developers the ability to leverage its extensive cmdlets, scripting capabilities, and remote management features across multiple platforms. With Rocky Linux 8’s stability and PowerShell’s flexibility, this setup becomes an invaluable resource for both system administration and DevOps workflows. Whether you’re managing Linux or Windows systems, PowerShell delivers a unified, efficient approach to streamline your tasks.

Looking for a Linux server expert? I provide top-tier administration, performance tuning, and security solutions for your Linux systems. Explore my Fiverr profile for details!