How to Install PowerShell on Ubuntu 16.04 LTS
To Install PowerShell on Ubuntu 16.04 LTS
PowerShell is a cross-platform automation and configuration tool/framework that works well with your existing tools and is optimized for dealing with structured data such as JSON, CSV, XML, etc and also on REST APIs, and object models. It includes a command-line shell, an associated scripting language and a framework for processing camlet. It is really so simple to install PowerShell on Ubuntu and this tutorial covers the ground on the same process.
Installing PowerShell
First, install PowerShell using official Ubuntu Microsoft Repository in the following manner.
root@linuxhelp:~# curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 79 100 79 0 0 39 0 0:00:02 0:00:01 0:00:01 39
deb [arch=amd64] https://packages.microsoft.com/ubuntu/16.04/prod xenial main
And then, make sure you update repositories with the help of the following command.
root@linuxhelp:~# apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu xenial InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease
.
.
Reading package lists... Done
Now, you can complete the PowerShell installation by making use of the following command.
root@linuxhelp:~# apt-get install powershell
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
.
.
Setting up powershell (6.0.1-1.ubuntu.16.04) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
After the installation, you can run the PowerShell, by just issuing this command “ pwsh” in the prompt:
root@linuxhelp:~# pwsh
PowerShell v6.0.1
Copyright (c) Microsoft Corporation. All rights reserved.
You have installed PowerShell, Let' s see some of its allied commands. If you want to create a directory, you need to run the following.
PS /home/user1> md linuxhelp PS /home/user1> ls Desktop Documents Downloads examples.desktop linuxhelp Music Pictures Public Templates Videos
If you want to get information on the current working directory, you can run the following command.
PS /home/user1> pwd
Path
----
/home/user1
The following command can be used to get the process that is running on the local computer.
PS /home/user1> ps
PID TTY TIME CMD
4848 pts/2 00:00:00 sudo
4849 pts/2 00:00:00 bash
5909 pts/2 00:00:01 pwsh
5972 pts/2 00:00:00 ps
You can also easily remove the directory in the following manner.
PS /home/user1> rd ./linuxhelp/ PS /home/user1> ls Desktop Documents Downloads examples.desktop Music Pictures Public Templates Videos
If you want to check the list of commands run during the process, run the following.
PS /home/user1> h
Id CommandLine
-- -----------
1 md linuxhelp
2 ls
3 pwd
4 ps
5 rd ./linuxhelp/
6 ls
You can also do it by making use of the history command.
PS /home/user1> history
Id CommandLine
-- -----------
1 md linuxhelp
2 ls
3 pwd
4 ps
5 rd ./linuxhelp/
6 ls
7. h
You can create a new item by making use of the ni command.
PS /home/user1> ni linuxhelp
Directory: /home/user1
Mode LastWriteTime Length Name
---- ------------- ------ ----
------ 07/02/18 6:20 PM 0 linuxhelp
A new item has been created, you can use the move command to move from one location to another.
PS /home/user1> move ./linuxhelp /home/user1/Desktop/ PS /home/user1> ls Desktop Documents Downloads examples.desktop Music Pictures Public Templates Videos
If you want to check the properties of the file, make sure you run the following command.
PS /home/user1/Desktop> gp linuxhelp
Directory: /home/user1/Desktop
Mode LastWriteTime Length Name
---- ------------- ------ ----
------ 07/02/18 6:20 PM 0 linuxhelp
You can exit from this, by making use of the following command.
PS /home/user1/Desktop> exit
With this, the installation and usage of PowerShell come to an end.
Comments ( 0 )
No comments available