Installing PowerShell on Linux
CentOS 7
This package also works on Oracle Linux 7.
Installation via Package Repository (preferred) – CentOS 7
PowerShell Core for Linux is published to official Microsoft repositories for easy installation (and updates).
# Register the Microsoft RedHat repository
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
# Install PowerShell
sudo yum install -y powershell
# Start PowerShell
powershell
After registering the Microsoft repository once as superuser, you just need to use sudo yum update powershell
to update PowerShell.
Installation via Direct Download – CentOS 7
Using CentOS 7, download the RPM package powershell-6.0.0_beta.1-1.el7.centos.x86_64.rpm
from the releases page onto the CentOS machine.
Then execute the following in the terminal:
sudo yum install ./powershell-6.0.0_beta.1-1.el7.centos.x86_64.rpm
You can also install the RPM without the intermediate step of downloading it:
sudo yum install https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-beta.1/powershell-6.0.0_beta.1-1.el7.centos.x86_64.rpm
Uninstallation – CentOS 7
sudo yum remove powershell
Red Hat Enterprise Linux (RHEL) 7
Installation via Package Repository (preferred) – Red Hat Enterprise Linux (RHEL) 7
PowerShell Core for Linux is published to official Microsoft repositories for easy installation (and updates).
# Register the Microsoft RedHat repository
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
# Install PowerShell
sudo yum install -y powershell
# Start PowerShell
powershell
After registering the Microsoft repository once as superuser, you just need to use sudo yum update powershell
to update PowerShell.
Installation via Direct Download – Red Hat Enterprise Linux (RHEL) 7
Download the RPM package powershell-6.0.0_beta.1-1.el7.centos.x86_64.rpm
from the releases page onto the Red Hat Enterprise Linux machine.
Then execute the following in the terminal:
sudo yum install ./powershell-6.0.0_beta.1-1.el7.centos.x86_64.rpm
You can also install the RPM without the intermediate step of downloading it:
sudo yum install https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-beta.1/powershell-6.0.0_beta.1-1.el7.centos.x86_64.rpm
Uninstallation – Red Hat Enterprise Linux (RHEL) 7
sudo yum remove powershell
Ubuntu 14.04
Installation via Package Repository – Ubuntu 14.04
PowerShell Core, for Linux, is published to package repositories for easy installation (and updates). This is the preferred method.
# Import the public repository GPG keys
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
# Register the Microsoft Ubuntu repository
curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
# Update apt-get
sudo apt-get update
# Install PowerShell
sudo apt-get install -y powershell
# Start PowerShell
powershell
After registering the Microsoft repository once as superuser, from then on, you just need to use sudo apt-get upgrade powershell
to update it.
Installation via Direct Download
Using Ubuntu 14.04, download the Debian package powershell_6.0.0-beta.1-1ubuntu1.14.04.1_amd64.deb
from the releases page onto the Ubuntu machine.
Then execute the following in the terminal:
sudo dpkg -i powershell_6.0.0-beta.1-1ubuntu1.14.04.1_amd64.deb
sudo apt-get install -f
Please note that
dpkg -i
will fail with unmet dependencies; the next command,apt-get install -f
resolves these and then finishes configuring the PowerShell package.
Uninstallation – Ubuntu 14.04
sudo apt-get remove powershell
Ubuntu 16.04
Installation via Package Repository – Ubuntu 16.04
PowerShell Core, for Linux, is published to package repositories for easy installation (and updates). This is the preferred method.
# Import the public repository GPG keys
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
# Register the Microsoft Ubuntu repository
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
# Update apt-get
sudo apt-get update
# Install PowerShell
sudo apt-get install -y powershell
# Start PowerShell
powershell
After registering the Microsoft repository once as superuser, from then on, you just need to use sudo apt-get upgrade powershell
to update it.
Installation via Direct Download – Ubuntu 16.04
Using Ubuntu 16.04, download the Debian package powershell_6.0.0-beta.1-1ubuntu1.16.04.1_amd64.deb
from the releases page onto the Ubuntu machine.
Then execute the following in the terminal:
sudo dpkg -i powershell_6.0.0-beta.1-1ubuntu1.16.04.1_amd64.deb
sudo apt-get install -f
Please note that
dpkg -i
will fail with unmet dependencies; the next command,apt-get install -f
resolves these and then finishes configuring the PowerShell package.
Uninstallation – Ubuntu 16.04
sudo apt-get remove powershell
SOURCE: https://github.com/PowerShell/PowerShell/blob/master/docs/installation/linux.md
Map Book for Experienced Bash users
The table below lists the usage of some basic commands to help you get started on PowerShell faster. Note that all bash commands should continue working on PowerShell session.
Bash | PowerShell | Description |
---|---|---|
ls | dir, Get-ChildItem | List files and folders |
tree | dir -Recurse | List all files and folders |
cd | cd, Set-Location | Change directory |
pwd | pwd, $pwd, Get-Location | Show working directory |
clear, Ctrl+L, reset | cls, clear | Clear screen |
mkdir | New-Item -ItemType Directory | Create a new folder |
touch test.txt | New-Item -Path test.txt | Create a new empty file |
cat test1.txt test2.txt | Get-Content test1.txt, test2.txt | Display files contents |
cp ./source.txt ./dest/dest.txt | Copy-Item source.txt dest/dest.txt | Copy a file |
cp -r ./source ./dest | Copy-Item ./source ./dest -Recurse | Recursively copy from one folder to another |
mv ./source.txt ./dest/dest.txt | Move-Item ./source.txt ./dest/dest.txt | Move a file to other folder |
rm test.txt | Remove-Item test.txt | Delete a file |
rm -r <folderName> | Remove-Item <folderName> -Recurse | Delete a folder |
find -name build* | Get-ChildItem build* -Recurse | Find a file or folder starting with ‘build’ |
grep -Rin “sometext” –include=”*.cs” | Get-ChildItem -Recurse -Filter *.cs | Select-String -Pattern “sometext” |
Recursively case-insensitive search for text in files
|