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.


Run the commands below in that sequence:

sudo apt update
sudo apt install -y wget apt-transport-https software-properties-common
wget -q
sudo dpkg -i packages-microsoft-prod.deb
sudo apt update && sudo apt upgrade
sudo apt install powershell


Using PowerShell directly from the terminal:


Will appear:

PowerShell 7.2.0
Copyright (c) Microsoft Corporation.
Type 'help' to get help.

To exit press:


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!'


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

For other distros see the here procedure.

shellscript terminal