Site icon CentLinux

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

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 Book: Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS 4th Edition (PAID LINK) by Travis Plunk, James Petty and Leon Leonhardt
Recommended Online Training: PowerShell Scripting and Automation for SQL Server DBA

Update Linux Operating System

By using a SSH client, connect with rockylinux-01.centlinux.com as root user.

Build cache for installed yum repositories.

# 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

First of all import the GPG key of Microsoft Official yum Repository by using rpm command.

# 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

Execute pwsh command to start PowerShell and execute some test commands thereon.

# 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

How to Install PowerShell on Linux 8 is a straightforward process that significantly enhances your system’s management capabilities. With PowerShell, you can automate tasks, manage configurations, and streamline administrative functions across different platforms, all from a powerful and versatile command-line interface.

If you need further assistance with installing PowerShell on Rocky Linux 8 or have other Linux-related needs, I offer professional services on Fiverr. Visit my Fiverr profile to explore my offerings, including installation support, system configuration, scripting, and more. Let me help you unlock the full potential of your Linux system with expert guidance and support.

Exit mobile version