Installing PowerShell Core on Ubuntu Linux
Installing PowerShell Core on Ubuntu Linux
If you’re looking to get started with PowerShell on Linux, specifically Ubuntu, this guide has you covered. We’ll walk through installing the necessary dependencies, setting up PowerShell Core, and configuring Visual Studio Code (VSCode) for editing PowerShell scripts.
Install Useful Tools
Before we install PowerShell Core, let’s make sure we have some helpful tools in place. We’ll start by updating the package manager:
sudo apt-get -y update
Next, let’s install a few key tools:
VIM
: a powerful text editornet-tools
: provides useful networking utilities likeifconfig
git-all
: ensures we have the full suite of Git tools installedsnapd
: the tool that allows us to install ‘snap’ packages, which we’ll use for PowerShell and VSCode
sudo apt -y install VIM
sudo apt -y install net-tools
sudo apt -y install git-all
sudo apt -y install snapd
Install PowerShell Core
Now that we have the dependencies in place, let’s install PowerShell Core. There are a couple of ways to do this:
Method 1: Using the GUI
- Open the Ubuntu Software store from the toolbar (the orange ‘A’ icon).
- Click the Search icon.
- Enter ‘PowerShell’ - you’ll see both the regular PowerShell icon and potentially a preview version.
- If you want to install through the GUI, just double-click the PowerShell item.
Method 2: Using the Command Line
-
PowerShell can be installed as a ‘snap’ package. Make sure you’ve installed
snapd
as mentioned earlier. -
Open a terminal window and run the following command to install PowerShell Core:
snap install powershell --classic
The
--classic
flag is required so the PowerShell snap can interact with the rest of your system. -
Launch PowerShell Core by running
pwsh
in your terminal. -
Test it out by running a few commands:
Get-Help Get-ChildItem $PSVersionTable
The
$PSVersionTable
command will show you the version of PowerShell you have installed.
Install VSCode
To edit PowerShell scripts, we’ll want to install Visual Studio Code (VSCode) as well. Similar to PowerShell, we can install VSCode as a snap package:
snap install --classic code
Once installed, be sure to install the PowerShell extension for VSCode. You can do this by:
- Clicking the Extensions icon on the left sidebar (the square puzzle piece).
- Searching for ‘PowerShell’ and clicking the ‘Install’ button.
You may also want to consider installing a few other useful extensions:
- Markdown All in One
- Markdown Preview Enhanced
- SQL Server (mssql)
- Bash Debug
Additional Configuration
If you need to install VSCode without using snaps, you can follow the Microsoft’s VSCode Linux installation documentation.
For PowerShell remoting and working with Docker, you’ll find additional setup instructions in the following documents:
Happy PowerShelling on Ubuntu!
This guide is based on content from Install PowerShell Core on Linux Ubuntu by Robert C. Cain.