How To Install PowerShell on Debian 11

In this article, we want to teach you How To Install PowerShell on Debian 11.

PowerShell is an open-source shell and scripting language built on top of Microsoft .NET technology. It aims to help tech pros who may not be software developers build efficient scripts and tools to help them do their job better.

How To Install PowerShell on Debian 11

Before you start to install PowerShell, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Debian 11.

Now follow the steps below to complete this guide.

Set up PowerShell on Debian 11

First, you need to update and upgrade your local package index with the following command:

sudo apt update && sudo apt upgrade

Then, you need to install the required packages on Debian 11 with the command below:

sudo apt install curl apt-transport-https gnupg2 -y

PowerShell is not available in the default Debian repository. So you need to add the PowerShell repo to the Debian repository with the command below:

sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-bullseye-prod bullseye main" > /etc/apt/sources.list.d/microsoft.list'

Next, add the GPG key with the following command:

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

Again, update your local package index:

sudo apt update

At this point, you can use the following command to install PowerShell on your server:

sudo apt install powershell -y

When your installation is completed, run the following command on Debian 11 to switch bash to the PowerShell:

pwsh

You will get the following output:

Output
PowerShell 7.2.3
Copyright (c) Microsoft Corporation.

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

PS /root>

If you want to download and install the latest version of Powershell in the future, you can run the commands below from your PowerShell console:

PS /root> sudo apt update && sudo apt upgrade

To exit from your PowerShell console, you can use the command below:

PS /root> exit

Remove PowerShell from Debian 11

If you no longer want to use PowerShell on your server, you can easily run the command below to remove it:

sudo apt remove powershell

Also, remove the repository with the following commands:

# sudo rm /etc/apt/sources.list.d/powershell.list
# sudo rm /etc/apt/sources.list.d/microsoft.list

Conclusion

At this point, you learn to Install PowerShell on Debian 11.

Hope you enjoy using it.

you may interested in other articles about PowerShell:

Install PowerShell on AlmaLinux 9 and RHEL 9

How To Install PowerShell on Ubuntu 22.04

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!