PowerShell for Mac is an extremely capable scripting language, and scripting equals automation potential. However, setting up PowerShell on a Mac might be a little challenging.
How To Install PowerShell For Mac?
Comparable to apt for Ubuntu or Yum for Fedora, Homebrew is a package manager for Mac. It is more practical than doing it manually when installing applications on a Mac.
By executing a few instructions, Homebrew enables you to install the most recent stable or preview PowerShell for Mac version on your computer.
1. Installing PowerShell for Mac
A stable version denotes that the program has undergone extensive testing and is ready for usage in a real-world setting.
These steps should be followed to install PowerShell on Mac using Homebrew:
- Open the Terminal program.
- Run the PowerShell installation command listed below. The cask portion is an extension that enables Homebrew to install macOS programs, whereas the brew portion is the essential Homebrew command.
- brew install –cask powershell
- When the installation is finished, an output similar to the one below will be shown. As of this writing, PowerShell 7.2.6 is the most recent stable version.
- Finally, launch PowerShell by running the code below.
- You’ll see something that looks like the image below, which shows PowerShell is active on your Mac.
2. Mac PowerShell installation
Microsoft also makes available PowerShell preview versions. These updates include novel features that shouldn’t be used in production because they haven’t been properly tested. To test out the new features, however, you might wish to install a preview version.
The procedures listed below can be used to install a preview version of PowerShell for Mac.
- To add the Homebrew versions repository, run the command below. PowerShell and other apps’ preview versions can be found in this repository.
- brew tap homebrew/cask-versions
- To install the most recent PowerShell Preview version, execute the command below.
- brew install –cask PowerShell-preview
- When the installation is finished, an output similar to the one below will be shown. The most recent version of PowerShell Preview is 7.3-preview.7 as of this writing.
3. Upgrading PowerShell for Mac
You can upgrade to the most recent version of PowerShell for Mac using Homebrew. Bug fixes and performance enhancements are frequently included in new versions.
Run the lines listed below in your Terminal to update PowerShell for Mac to the most recent stable version. The first command modifies the list of Homebrew packages. PowerShell for Mac is updated to the most recent stable and preview versions with the second and third commands, respectively.
- brew update
- brew upgrade PowerShell –cask
- brew upgrade PowerShell-preview –cask
4. Installing PowerShell for Mac Using PKG Files
Microsoft also provides PKG installer files for PowerShell for Mac. These files are available for download from the PowerShell GitHub releases page.
- Download the PKG file powershell-7.2.2-osx-x64.pkg to your macOS device.
- Double-click the file and follow the on-screen instructions to install it.
- Set up OpenSSL. PowerShell remoting and CIM activities require OpenSSL.
If you prefer using the GUI when installing software as opposed to the command line, the PKG installer is for you. Observe these procedures to install PowerShell using a PKG file:
- Click the Assets drop-down option on the PowerShell GitHub current releases page after opening your browser.
- Select the PowerShell PKG file link according to the CPU type of your computer. Choose the arm64 option if your Mac has an M1 chip; otherwise, use the x64 link.
- The file should be saved to your Downloads folder.
- Double-click the downloaded file to start the installer, then select Open.
- On the Introduction screen, click Continue.
- Only the current user account is supported for installation via PowerShell for Mac. A unique installation destination path cannot be selected.
- On the Installation type screen, click Install.
- To complete the installation, click Close on the Summary screen.
- Type PowerShell into the Search field to run PowerShell from the Launchpad. To open PowerShell, select it in the list of results.
5. Installing PowerShell for Mac Using Dot Net Developer CLI
Using the Dot Net Developer CLI is an additional method for installing PowerShell for Mac. You can create, construct, run, and publish DOTNET programs using the cross-platform DOTNET command-line interface (CLI), which is called the Dot Net Developer CLI.
- This approach might be the most convenient way to install PowerShell if you’re a developer and already have dotnet CLI set up on your Mac.
- To install PowerShell via the dotnet CLI, use the command below.
- dotnet tool install –global PowerShell
- When the installation is finished, an output similar to the one below will be shown.
- Run the cat command shown below to update the PATH variable. With the help of this command, you can run PowerShell from any directory by adding the PowerShell installation directory to the PATH environment variable.
- To refresh the environment variable in your terminal session, type the command below.
- zsh -l
- Run the pwsh command in your Terminal to start PowerShell.