Questions & Answers

Win10: Using symbolic links in the PATH variable

Here's the deal. I want to use a symbolic link to the latest installed Java version and create a symbolic link. The PATH variable shall contain the symbolic link as entry. The link is not resolved, though. Why?


$> dir C:\Program\ Files\Java
C:\Program\ Files\Java\jdk-1.14.1\
C:\Program\ Files\Java\jdk-latest.lnk  # link to jdk-1.14.1

$> echo %PATH%
C:\Program\ Files\Java\jdk-latest\bin

$> java --version
The command "java" is either written wrong or couldn't be found.
2023-01-17 00:49:26
A .lnk shell link is not a filesystem symbolic link. It's a binary file that the high-level Windows shell API processes. It doesn't even have to target a real file or directory; it can be anything in the shell namespace.
2023-01-17 00:49:26
You want either a directory junction (i.e. a bind mountpoint) created in CMD via mklink /j jdk-latest jdk-1.14.1 or a directory symlink created via mklink /d jdk-latest jdk-1.14.1 (this is a relative link; you could also link to the absolute path). A bind mountpoint can be created without any special privilege. Creating a symlink requires SeCreateSymbolicLinkPrivilege. If this privilege is not assigned explicitly to the user or one of the user's non-administrator groups, then it's only available by elevating to full administrator access.
Answers(1) :

New-Item cmdlet with -ItemType SymbolicLink can be used to create symbolic link to file or folder.

Suppose, you have 2 folders containing 2 different versions of nodejs


We need one symbolic link, say rel which will point to one of the nodejs folders.

Add C:\Program\Files\nodejs\rel to PATH environment variable

Point rel to node v14.18.0

New-Item -Type SymbolicLink -Path .\rel -Target .\node-v14.18.0-win-x64 -Force

Verify node version

PS C:\Users\pvaddepa> node -v

Use -Force to update the symbolic link to point to node v14.20.0.

New-Item -Type SymbolicLink -Path .\rel -Target .\node-v14.20.0-win-x64 -Force

Verify the node version

PS C:\Users\pvaddepa> node -v

See New-Item example .