Skip to main content

RHEL: Install Powershell Core

Illustration: Microsoft loves Linux

Check if Powershell Core is installed by trying running pwsh command.

[tuyendq@rhel1 ~]$ pwsh
-bash: pwsh: command not found
[tuyendq@rhel1 ~]$ sudo yum install -y powershell
Loaded plugins: product-id, search-disabled-repos, subscription-manager
epel/x86_64/metalink                                     |  22 kB     00:00
epel                                                     | 4.7 kB     00:00
(1/3): epel/x86_64/updateinfo                              | 986 kB   00:00
(2/3): epel/x86_64/primary_db                              | 6.6 MB   00:00
(3/3): jdoss-wireguard/x86_64/primary_db                   | 3.8 kB   00:01
No package powershell available.
Error: Nothing to do
[tuyendq@rhel1 ~]$ curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   193  100   193    0     0    400      0 --:--:-- --:--:-- --:--:--   400
[packages-microsoft-com-prod]
name=packages-microsoft-com-prod
baseurl=https://packages.microsoft.com/rhel/7/prod/
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc
[tuyendq@rhel1 ~]$ sudo yum install -y powershell                               Loaded plugins: product-id, search-disabled-repos, subscription-manager
packages-microsoft-com-prod                              | 2.9 kB     00:00
packages-microsoft-com-prod/primary_db                     | 162 kB   00:00
Resolving Dependencies
--> Running transaction check
---> Package powershell.x86_64 0:6.2.0-1.rhel.7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package       Arch      Version           Repository                      Size
================================================================================
Installing:
 powershell    x86_64    6.2.0-1.rhel.7    packages-microsoft-com-prod     55 M

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

Total download size: 55 M
Installed size: 55 M
Downloading packages:
warning: /var/cache/yum/x86_64/7Server/packages-microsoft-com-prod/packages/powershell-6.2.0-1.rhel.7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID be1229cf: NOKEY
Public key for powershell-6.2.0-1.rhel.7.x86_64.rpm is not installed
powershell-6.2.0-1.rhel.7.x86_64.rpm                       |  55 MB   00:10
Retrieving key from https://packages.microsoft.com/keys/microsoft.asc
Importing GPG key 0xBE1229CF:
 Userid     : "Microsoft (Release signing) "
 Fingerprint: bc52 8686 b50d 79e3 39d3 721c eb3e 94ad be12 29cf
 From       : https://packages.microsoft.com/keys/microsoft.asc
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : powershell-6.2.0-1.rhel.7.x86_64                             1/1
  Verifying  : powershell-6.2.0-1.rhel.7.x86_64                             1/1

Installed:
  powershell.x86_64 0:6.2.0-1.rhel.7

Complete!
[tuyendq@rhel1 ~]$

Let's start powershell by running pwsh command and check system up time with new Get-Uptime cmdlet

[tuyendq@rhel1 ~]$ pwsh
PowerShell 6.2.0
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /home/tuyendq> Get-Uptime

Days              : 93
Hours             : 11
Minutes           : 47
Seconds           : 55
Milliseconds      : 0
Ticks             : 80776750000000
TotalDays         : 93.4916087962963
TotalHours        : 2243.79861111111
TotalMinutes      : 134627.916666667
TotalSeconds      : 8077675
TotalMilliseconds : 8077675000


PS /home/tuyendq>

Check Powershell version by echoing built-in variable $PSVersionTable

PS /home/tuyendq> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Linux 3.10.0-957.1.3.el7.x86_64 #1 SMP Thu Nov …
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS /home/tuyendq>

Popular posts from this blog

Linux command: tail

tail - output the last part of files

Linux command: top

NAME        top - display Linux processes SYNOPSIS        top -hv|-bcHiOSs -d secs -n max -u|U user -p pid -o fld -w [cols]        The traditional switches `-' and whitespace are optional. DESCRIPTION        The  top program provides a dynamic real-time view of a running system.  It can display        system summary information as well as a list of processes or  threads  currently  being        managed  by  the  Linux  kernel.  The types of system summary information shown and the        types, order and size of information displayed for processes are all user  configurable        and that configuration can be made persistent across restarts.        The  program  provides a limited interactive interface for process manipulation ...

Linux command: printenv

printenv - print all or part of environment NAME        printenv - print all or part of environment SYNOPSIS        printenv [OPTION]... [VARIABLE]... DESCRIPTION        Print  the  values  of the specified environment VARIABLE(s).  If no VARIABLE is speci‐        fied, print name and value pairs for them all.        -0, --null               end each output line with NUL, not newline        --help display this help and exit        --version               output version information and exit        NOTE: your shell may have its own version of printenv,  which  usually  supersedes  the        version  described  here.  Please refer to your shell's documentation for d...