Learn how to install Microsoft PowerShell on a Linux operating system
PowerShell has been a staple of Windows for many years; But recently, Microsoft has made significant changes to it. PowerShell is now both open source and cross-platform, and is available not only on Windows but also on macOS and Linux. This new version is the future of PowerShell. It does not matter if you want to use it professionally in Linux or just get acquainted with it, it is not difficult to install PowerShell. Follow the Microsoft PowerShell tutorial on Linux operating system with Zomit.
Download and install PowerShell on Linux
PowerShell on Linux is not exactly the same as Windows, and Windows-specific modules and commands are not usable. Microsoft is moving away from PowerShell and into a cross-platform affair.
Follow the steps below to install PowerShell on Linux:
- Go to the PowerShell release page.
- Download a downloader that is compatible with your Linux distribution.
- Find the downloaded file on your device.
- Double-click to install.
The installation process will now be relatively short, using a software downloader that may vary depending on the Linux distribution.
Because PowerShell is a command line tool in Linux and is not a common program, you can not run it directly from your desktop GUI and you have to run it from the terminal.
If you are using Arch Linux, you can install PowerShell from AUR by getting the latest binary version.
You can also use the Snap Store to install PowerShell.
According to official documents, Microsoft PowerShell 7 is not supported on Ubuntu 20.04 LTS; But this is not the case. In this tutorial, PowerShell is installed on Ubuntu 20.04. Although there were problems with using direct download; But the installation went well.
How to launch PowerShell inside the terminal
To use PowerShell, open a new terminal window and enter this simple command.
After a command prompt notification from yourusername @ yourlinuxmachine To PS / home / yourusername Changes.
You are now ready to use PowerShell on your Linux device. Whenever you want to use it, simply enter the run command and exit by typing exit.
But if you are going to use PowerShell a lot, you may need to set it as the default shell for the Linux terminal.
Set PowerShell as the default terminal shell
The advantage of PowerShell is that it does not completely replace or overwrite your existing skin; So any Linux command you can normally enter can also be entered in PowerShell. If you plan to use PowerShell a lot, you can set it as your default skin without any worries.
There are several different ways to achieve this, one of the simplest of which is to change the default in / etc / passwd, and if you install it as Snap, you will probably see a slight difference in the setup steps.
First, make sure that PowerShell is added to / etc / shells as a valid login shell.
- In the terminal sudo nano / etc / shells Enter (replace nano with your favorite text editor if necessary).
- If you see an entry for pwsh, you can close the file.
- If you need to add PowerShell, / usr / bin / pwsh Type at the bottom of the text file.
- If you installed PowerShell via SNAP, instead / usr / bin / pwsh Should / snap / bin / pwsh Add.
- Pressing the keys ctrl + X And selection yes Exit nano to save changes.
Then in the terminal, follow these steps:
1. sudo nano / etc / passwd Enter (replace nano with your custom text editor if necessary).
۲. Until you see the input to / bin / bash Is over, scroll down.
3. This input to / bin / pwsh Or if you have installed from SNAP to / snap / bin / pwsh change it.
4. Exit and save the file.
5. Log out of your PC and log in again.
After re-logging in and opening a new terminal window, PowerShell should run immediately instead of the standard bash shell.
We hope you find this tutorial useful. If you have experience installing Microsoft PowerShell on a Linux operating system, please share it with us and Zomit users.