Use open source commands in Powershell

Set your path on Windows so you can use open source commands.
Register or Login to like
bash logo on green background

Opensource.com

When you launch an application on an operating system, there are certain code libraries and utility applications that your OS needs to use for that app to run. Your OS knows how to find these libraries and utilities because it has a system path, a map to common shared data that lots of apps need. Every OS has this, but users aren’t usually aware of it because they don’t usually need to care about it. However, when you start coding or using special network utilities or commands, you might care about your own PATH variable.

The PATH variable makes it so that you can save commands to a consistent location, and use them from anywhere on your system using the command prompt or the more powerful (and open source) Powershell.

For instance, say you want to install the open source application pscp.exe, a command-line interface to the famous PuTTY OpenSSH client on Windows. You can download it to your hard drive, but how does your command-line know that it exists? Well at first, it doesn’t:
 

PS> pscp
pscp: The term 'pscp' is not recognized as the name of a cmdlet, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

If you’re using an open source command line, such as Powershell or Cmder, you get a useful error hinting that this might be a problem with your path (or the lack thereof). Here’s how to solve that problem.

Setting a PATH

  1. First, create a folder called App on your Desktop.

  2. Next, right-click on the Windows menu in the bottom left corner of your screen, and select System.

Image of the Windows menu system.

(Alan Smithee, CC BY-SA 4.0)

  1. In the System window that appears, click the link to Advanced system settings on the left of the window.

  2. In the System properties window that appears, click the Environment variables button at the bottom of the window.

Image Windows system enviroment variables.

(Alan Smithee, CC BY-SA 4.0)

  1. In the Environment variables window, click the New button under the User variables panel.
Image of new Windows enviroment variables.

(Alan Smithee, CC BY-SA 4.0)

  1. In the dialog box that appears, enter PATH for the Variable name field, and %USERPROFILE\Desktop\App for the Variable value field. Click the OK button to save your changes.
Image of Windows path set.

(Alan Smithee, CC BY-SA 4.0)

Place commands and applications you want to have access to from a command prompt in Desktop\Apps and Powershell, Cmder, and even Cmd will find them:
 

PS> pscp –version
pscp: Release 0.XY
Build platform: 64-bit x86 Windows
PS>

Automatic PATH settings

Many applications get automatically added to the system path during installation. However, not all of them do, either because you missed a check box during the install process, or because the application developer expects you to add it yourself. When automatic paths fail, you now know how to forge your own path.

Avatar
I like my privacy.

3 Comments

Since the focus here is on "commands", I suspect some readers would appreciate hearing that they can set system env vars from the command line, not just the gui. See the `setx` command, available since Windows XP. Use its /m arg (since Windows 7) to set the var as a system env var--though curiously that won't take effect in the current command window. More at https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/setx.

There is also an available powershell cmdlet, SetEnvironmentVariable.

What is happening here? Opensource.com used to be about, well, open source. Why are articles about proprietary software appearing here?

To use the open source pscp application in the open source Powershell application on the non-open source Windows OS, you need to know how to add it to the system's path. This article demonstrates that.

(We did attempt to demonstrate the same thing on ReactOS instead, but the process is considerably different.)

In reply to by William Peckham

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.