Setup: PowerShell on a Mac or Linux
PowerShell 7 runs on a Mac and on Linux too, installed with Homebrew or Microsoft's package for Ubuntu and started with pwsh, with a few differences in paths and a few Windows-only lessons.
Novice · PowerShell · Operating System · Updated
After this lesson you can
- Choose the command that installs PowerShell 7: Homebrew on a Mac, Microsoft's package on Ubuntu, winget on Windows
- Start PowerShell 7 with pwsh, and say what changes on a Mac or Linux: paths with /, capital letters, Windows-only lessons
Key takeaways
- On a Mac, Homebrew installs PowerShell 7 with brew install --cask powershell. On Ubuntu, Microsoft's own package installs it with apt-get.
- You start PowerShell 7 by typing pwsh in the terminal you already have, and leave it again with exit.
- Paths use / and have no drive letter, your home folder is /Users/you or /home/you, and on Linux capital letters in names matter.
- The lessons about administering Windows, Out-GridView and small windows are Windows only and say so. Everything else works the same.
Your laptop is a Mac, or your school's lab runs Linux, and a project's instructions are written in PowerShell. That's no problem: PowerShell 7 runs on macOS and Linux as well as Windows, and almost every command in this course works the same on all three. This lesson installs it, starts it, and points out the few things that differ.
On Windows? Follow Setup: Windows Terminal and PowerShell 7 instead.
Open a terminal
Your computer already has a terminal, running a different shell (the program that reads your commands):
- On a Mac, open Terminal: press Cmd+Space, type
terminaland press Enter. It runs a shell called zsh. - On Ubuntu Linux, press Ctrl+Alt+T. It runs a shell called bash.
You install PowerShell from that shell, so the install commands below are written for zsh and bash, not for PowerShell.
On a Mac: Homebrew
Homebrew is a package manager for the Mac: a tool that installs apps when you name them, like an app store you type into. If you don't have it yet, the front page of brew.sh gives the one line that installs it. Then install PowerShell 7:
brew install --cask powershell
--cask tells Homebrew that PowerShell comes as a ready-made app package. Homebrew may ask for your Mac's password, because the package installs for everyone on the Mac. Later, brew upgrade updates PowerShell along with everything else Homebrew installed.
On Ubuntu: Microsoft's package
On Ubuntu, PowerShell comes from Microsoft's own package source, which you add first. These are the lines from Microsoft's instructions for Ubuntu 22.04, 24.04 and 26.04, in order:
sudo apt-get update
sudo apt-get install -y wget apt-transport-https software-properties-common
source /etc/os-release
wget -q https://packages.microsoft.com/config/ubuntu/$VERSION_ID/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install -y powershell
sudo runs a command as the administrator, so it asks for your password. The first six lines tell Ubuntu where Microsoft's packages live ($VERSION_ID fills in your Ubuntu version), and the last two install PowerShell with apt-get, Ubuntu's package manager. For other kinds of Linux, Microsoft's page Install PowerShell on Linux lists their commands.
Start it: pwsh
PowerShell 7's program is called pwsh. Type it in your terminal and press Enter:
pwsh
The prompt changes to PS and your folder, such as PS /Users/sam> on a Mac or PS /home/sam> on Linux: you're in PowerShell now. Check the version the same way as on Windows:
$PSVersionTable.PSVersion
It shows a table with 7 under Major. Then make your practice folder:
New-Item -ItemType Directory -Force -Path "$HOME/terminal-practice" | Out-Null
It prints nothing when it works (| Out-Null hides PowerShell's answer). Type exit to leave PowerShell and go back to zsh or bash.
What's different on a Mac or Linux
- Paths use
/and have no drive letter. Your home folder is/Users/samon a Mac and/home/samon Linux, so where this course writes$HOME\terminal-practice, you write$HOME/terminal-practice. - Capital letters can matter in file and folder names. On Linux,
Photosandphotosare two different folders. A Mac usually treats them as one, but write every name exactly as it's spelled, and your commands work on both. - There's no Windows Terminal: you use Terminal on a Mac or your Linux terminal, and type
pwshto start PowerShell. - A few lessons are Windows only, and say so at the top: Module 8, Administering Windows, and the lessons on
Out-GridViewand small windows. - Everything else is the same. The commands, the objects, the scripts and the exercise checks all work in PowerShell 7 on every system.
Check yourself
2 questions to try on the lesson page.
So what
PowerShell isn't only for Windows. What you learn here works on a Mac, a Linux laptop and the Linux servers that run much of the web.