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:
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
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
Once the installation is complete, launch PowerShell on Debian by running the following command:
pwsh
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
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:
Next, select the software Install app:
Now click on the Install option to install PowerShell on Debian using its Deb file:
After the installation is completed, launch it in the terminal by executing:
pwsh
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
Next, to confirm the installation of PowerShell on Debian through Snap, you can list the Snap-installed apps on Debian:
sudo snap list
Next, launch PowerShell on Debian installed via Snap using:
pwsh
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
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'
Next, to properly add the PowerShell repo on Debian update its default package installer packages list:
sudo apt update
Now install PowerShell using the Debian default app installer by running the following command:
sudo apt install -y powershell
To launch the PowerShell on Debian installed via its repository, execute:
pwsh
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 |
1 | Get-Process | Gives information about running processes |
2 | Get-ChildItem | Gives information about files and folders (alias of directories) |
3 | Write-Host [text] | Writes text to the console |
4 | Stop-Process [Process-ID] | To stop any running process |
5 | Remove-item [file-path-file-name] | Deletes items (use with caution) |
6 | Get-command | Lists all the commands cmdlets |
7 | New-Item [file-name] | Creates a file in the current directory unless a specific directory is not given |
8 | Move-Item [file-name] [destination-path] | Moving a file to another destination or directory |
9 | New-Item -Path [directory-path-&-file-name] -ItemType directory | Adding a directory using PowerShell on Linux |
10 | Get-ChildItem -Path “C:\Users\YourName\Documents” -Force | Display 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:
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.