How to Install Microsoft PowerShell on Debian 12

PowerShell is a command line shell tool primarily designed for the Windows operating system and is often used for system administration, configuration management, data analysis, and reporting. On Debian or other Linux distributions, some other tools like apt, bash, and systemctl provide the same functionality.

However, if you’re already familiar with PowerShell and have existing scripts that you want to partially reuse, or you need some specific PowerShell cmdlets that have compatible implementations in PowerShell Core. Then you should install and use PowerShell on Debian, this article will explain all the ways to install PowerShell on Debian 12.

4 Ways To Install Microsoft PowerShell on Debian 12?

For Debian, there’s an open-source project called “PowerShell Core” that allows running some PowerShell cmdlets. However, functionality is limited compared to Windows PowerShell, as not all cmdlets might be available or work identically. There are 4 ways to install PowerShell on Debian 12:

1: Through Microsoft PowerShell Deb file

The first method to install Microsoft PowerShell on Debian is using its Deb file which can downloaded from Github by selecting the desired version:

Downloading PowerShell Deb file on Debian using GitHub

Alternatively, you can use the download link of the Deb file to download it as in the command below:

wget https://github.com/PowerShell/PowerShell/releases/download/v7.4.3/powershell_7.4.3-1.deb_amd64.deb

Downloading PowerShell Deb file on Debian from GitHub using terminal

Once the file is downloaded install PowerShell on Debian either using the apt package manager or dpkg app installer, the below command uses the dpkg package manager:

sudo apt install ./powershell_7.4.3-1.deb_amd64.deb

Installing Microsoft PowerShell on Debian using its Deb file via apt

Once the installation is complete, launch PowerShell on Debian by running the following command:

pwsh

Launching PowerShell on Debian installed via its deb file

Additionally, if you encounter any errors while launching PowerShell on Debian then execute the below command which will install any missing dependencies if there are any:

sudo apt-get install -f

Installing missing dependencies for PowerShell on Debian

2: Through Debian Software Install App

Another way to install Microsoft PowerShell using its Deb file is through the Debian 12 Software App. First open the deb file in this app, for that move to the Deb file directory and click on Open With option:

Opening PowerShell Deb file in Software Install app in Debian

Next, select the software Install app:

Opening PowerShell Deb file in Software Install app in Debian

Now click on the Install option to install PowerShell on Debian using its Deb file:

Installing PowerShell on Debian using its deb file via software Install app

After the installation is completed, launch it in the terminal by executing:

pwsh

Launching PowerShell on Debian installed via Software Install app

3: Through Snap App Installer

To install PowerShell on Debian, you can use the third-party app installer known as Snap app installer, and for that execute the below command. This will install the PowerShell classic version:

sudo snap install powershell --classic

Installing PowerShell on Debian using Snap Package Installer

Next, to confirm the installation of PowerShell on Debian through Snap, you can list the Snap-installed apps on Debian:

sudo snap list

Listing Snap installed apps on Debian to verify PowerShell installation

Next, launch PowerShell on Debian installed via Snap using:

pwsh

Launching PowerShell on Debian installed via Snap app installer

4: Through Microsoft PowerShell Repository

The last method to install PowerShell on Debian is using Microsoft PowerShell’s official repository. In the process of installing PowerShell via its repository, you need to add its key and for that execute the below command:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EB3E94ADBE1229CF

Adding GPG key for PowerShell on Debian for its repository

Now add the PowerShell repository by Microsoft on Debian in its sources.list.d directory validated by the GPG Key added previously:

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'

Adding Microsoft PowerShell repository on Debian

Next, to properly add the PowerShell repo on Debian update its default package installer packages list:

sudo apt update

Updating Debian apt packages list to add PowerShell repository

Now install PowerShell using the Debian default app installer by running the following command:

sudo apt install -y powershell

Installing PowerShell on Debian using its repository

To launch the PowerShell on Debian installed via its repository, execute:

pwsh

Launching PowerShell on Debian installed via Microsoft PowerShell repository.

Further, if you are new to PowerShell or you are looking for some basic commands for PowerShell, then see the table below that lists PowerShell commonly used commands:

Sr No.Command Description 
1Get-ProcessGives information about running processes
2Get-ChildItemGives information about files and folders (alias of directories)
3Write-Host [text]Writes text to the console
4Stop-Process [Process-ID]To stop any running process
5Remove-item [file-path-file-name]Deletes items (use with caution)
6Get-commandLists all the commands cmdlets
7New-Item [file-name]Creates a file in the current directory unless a specific directory is not given
8Move-Item [file-name] [destination-path]Moving a file to another destination or directory
9New-Item -Path [directory-path-&-file-name] -ItemType directoryAdding a directory using PowerShell on Linux
10Get-ChildItem -Path “C:\Users\YourName\Documents” -ForceDisplay hidden files

 

Note: There are two things that you should keep in mind while installing PowerShell on Debian. One is that some blogs have written that it is by default available in apt package manager but it is not as you can see in the image below:

unable to locate PowerShell Package error on Debian While installing it throuigh apt

The second thing is that the Microsoft PowerShell repository is for Debian 11, but it works OKAY on Debian 12 as well, so don’t worry about that. The last and third thing you should keep in mind is that most of the blogs have used the sudo apt-key add –. You won’t be able to do that as the process will stuck on downloading, instead use the key ID in .asc file as I did.

Conclusion

To install PowerShell on Debian there are primary four ways, these include using the Microsoft PowerShell Deb file, the Debian Software Install app, the Snap app installer, and using PowerShell repository. The best way to install PowerShell on Debian 12 is by using its deb file as you can install older versions of it and this method is also recommended by Microsoft as well. 

Index
Scroll to Top