DebianDebian Based

How To Install PowerShell on Debian 12

Install PowerShell on Debian 12

In this tutorial, we will show you how to install PowerShell on Debian 12. PowerShell is a powerful cross-platform shell and scripting language designed by Microsoft. With its extensive command-line capabilities and scripting framework, it has become a popular choice for system administrators, developers, and IT professionals. Unlike traditional shells, PowerShell uses cmdlets to perform tasks, making it highly efficient and flexible.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of PowerShell on a Debian 12 (Bookworm).

Prerequisites

  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for PowerShell.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install PowerShell on Debian 12 Bookworm

Step 1. Before installing PowerShell, it is recommended to update the system to ensure that all packages are up to date. You can do this by running the following command in the terminal:

sudo apt update
sudo apt install curl gnupg apt-transport-https

This command will refresh the repository, allowing you to install the latest versions of software packages.

Step 2. Installing PowerShell on Debian 12.

  • Method 1: Installing PowerShell via Snap Package

Snap is not included by default in Debian 12, so let’s install it:

sudo apt install snapd

To find the PowerShell snap package, use the snap search command:

snap find powershell

Now install PowerShell using the snap package:

sudo snap install powershell --classic

To verify the installation, type:

pwsh --version
  • Method 2: Using the Package Manager (apt)

You need to import the Microsoft GPG key to verify the authenticity of the PowerShell package. You can do this by running the following command:

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

After importing the GPG key, you need to add the Microsoft package repository to the system. You can do this by running the following command:

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

Now that the Microsoft package repository has been added, you can install PowerShell by running the following command:

sudo apt update
sudo apt install powershell

After the installation is complete, you can verify that PowerShell is installed by running the following command:

pwsh --version

Step 3. Launching PowerShell on Debian.

Now that PowerShell is up and running on your Debian 12 system, let’s get familiar with basic commands and functionality:

A. Launching PowerShell

Simply type pwsh in your terminal to launch PowerShell.

Install PowerShell on Debian 12

B. Basic PowerShell Commands and Syntax

PowerShell’s syntax is designed to be intuitive and consistent. Let’s explore some basic commands:

  • Get-Help: Retrieve help information for a cmdlet.
  • Get-Process: List running processes.
  • Get-Service: Display the status of services.
  • Get-ChildItem: List files and directories in the current location.

C. Interacting with the Filesystem

PowerShell allows seamless interaction with the filesystem using cmdlets like Get-ChildItem, Set-Location, New-Item, Remove-Item, and more.

D. Managing Packages Using PowerShell

PowerShell facilitates the installation, update, and removal of packages through cmdlets like Install-Package, Update-Package, and Uninstall-Package.

Step 4. Troubleshooting Common Issues.

As with any software, you may encounter issues while working with PowerShell on Debian 12. Let’s address some common problems and their solutions.

A. Addressing Common Installation Problems

  • Package Not Found: Ensure the repository and key installation steps were executed correctly.
  • PowerShell Command Not Found: Double-check the environment variables setup or restart the terminal session.

B. Troubleshooting Issues with PowerShell Commands

  • Incorrect Syntax: Review the cmdlet’s syntax in the official documentation or use the Get-Help command.
  • Access Denied: Ensure you have sufficient permissions to execute the command.

Congratulations! You have successfully installed PowerShell. Thanks for using this tutorial for installing the latest version of PowerShell on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official Microsoft website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button