Search

How to Install PowerShell on Ubuntu and Getting Started

In addition to a tip on how to proceed with any other Linux distribution.


How to Install PowerShell on Ubuntu and Getting Started

PowerShell is a task-based command-line shell and scripting language developed in .NET. Initially just a Windows component.

You can install it on any distribution Linux . In this article we’ll look at how to do this on Ubuntu 21.04 or higher. And the first steps, plus tips for other distros.


Installation

Run the commands below in that sequence:

sudo apt update
sudo apt install -y wget apt-transport-https software-properties-common
wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt update && sudo apt upgrade
sudo apt install powershell


Use

Using PowerShell directly from the terminal:

pwsh

Will appear:

PowerShell 7.2.0
Copyright (c) Microsoft Corporation.

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

To exit press:

exit


Creating a basic script

Let’s run a Hello, World!.

Create the file and insert the content into it:

nvim hello-world.pwsh

Write-Host 'Hello, World!'

Rotate:

pwsh hello-world.pwsh

Or simply:

nvim hello-world.pwsh

#!/usr/bin/env pwsh
Write-Host 'Hello, World!'

Give execution permission and run:

chmod +x hello-world.pwsh
./hello-world.pwsh

For other distros see the here procedure.


shellscript terminal


Share



Comments