DEV Community

Gianluigi Disconzi
Gianluigi Disconzi

Posted on

3 1

Configure Path variable in Powershell

Scenario: for whatever reason you have to develop on a Windows machine and you're not an administrator. Your company enforces the same old Java version on all machines, but you want to try out a more recent one.
After you download a JDK binary distribution in a folder of your choice, it's really easy to set up your IDE to work with that, but what if you want to run Java from Powershell?
Typically your machine will be set up with a system Path variable which points to the old Java version, and that cannot be changed. You try to change the Path in your user variables adding the location to your brand newly downloaded JDK. Hooray right?

Well... no 😥

It turns out that user Paths are postponed to system Paths, and when looking for an executable Windows picks the first match.

Luckily for us, it turns out there's a workaround for that! Similarly to bash with its .bashrc file, Powershell supports init scripts.
To create an init script, run this command from Powershell:

New-Item $profile -Type File -Force

Go to your Documents folder, you'll find a new WindowsPowerShell subfolder which contains a Powershell script named Microsoft.PowerShell_profile.ps1. Edit that file and add a line like this:

 $Env:Path="C:\Users\my-user-name\apps\my-jdk-folder\bin;"+$Env:Path

Save and open a new Powershell instance: the script will run automatically when a new shell instance is created. Now you can see the new Path variable with the following command:

echo $env:Path

Tiugo image

Fast, Lean, and Fully Extensible

CKEditor 5 is built for developers who value flexibility and speed. Pick the features that matter, drop the ones that don’t and enjoy a high-performance WYSIWYG that fits into your workflow

Start now

Top comments (0)

Image of Quadratic

Free AI chart generator

Upload data, describe your vision, and get Python-powered, AI-generated charts instantly.

Try Quadratic free

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay