Everyone knows, that sometime soon, Microsoft will support the PowerShell installation in Ubuntu 20.04. But, in the meantime, there’s another way. And, this also applies to WSL (Windows Subsystem for Linux) Ubuntu 20.04.
It is the way!
First, you must follow the instructions for installing .NET Core for Ubuntu 20.04 from the Microsoft Documentation: https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu#2004-
Basically, the following commands will install both the .NET Core SDK and the Runtime components:
## Install the SDK wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb sudo apt-get update; \ sudo apt-get install -y apt-transport-https && \ sudo apt-get update && \ sudo apt-get install -y dotnet-sdk-3.1 ## Install Runtime sudo apt-get update; \ sudo apt-get install -y apt-transport-https && \ sudo apt-get update && \ sudo apt-get install -y aspnetcore-runtime-3.1 sudo apt-get install -y dotnet-runtime-3.1
So, after the .NET Core gets installed, then proceed to install the “.NET Global” tool:
## - Install .NET Interactive: dotnet tool install --global Microsoft.dotnet-interactive ## Install PowerShell Global: dotnet tool install --global PowerShell
Almost there! There’s one more step we need to do. If you try executing PowerShell, the system can’t find the program.
To resolve the issue of PowerShell not found, we need to add the path to the .NET Global Tools components so that PowerShell can start.
In my case, I open my VIM editor using “sudo” so I can modify the “~/.bashrc” file.
## Add .NET Tools path in Bashrc $ sudo vim ~/.bashrc ## - Add path to .NET Tools: export PATH=$PATH:~/.dotnet/tools :wq ## - Refresh session after updating bashrc: $ source ~/.bashrc
At this point, now you can start using PowerShell 7 in Ubuntu 20.04.
But, how to update PowerShell?
Simple! The following two commands will update .NET Tools when the update becomes available:
dotnet tool update -g --add-source "https://dotnet.myget.org/F/dotnet-try/api/v3/index.json" Microsoft.dotnet-interactive dotnet tool update -g powershell
And, the following command will confirm the latest version of both the .NET Tools installed in the system:
dotnet tool list --global
Now, go ahead and have fun with PowerShell.
Happy PowerShelling!!