I followed the guide for switching java versions but it somehow seems to not work in my case.
I have both openjdk11 and openjdk13 installed from the java bucket:
$ scoop info openjdk11
Name: openjdk11
Description: Official production-ready open-source builds of OpenJDK 11
Version: 11.0.2-9
Website: https://jdk.java.net/11
License: GPL-2.0-only WITH Classpath-exception-2.0 (https://spdx.org/licenses/GPL-2.0-only WITH Classpath-exception-2.0.html)
Manifest:
C:\Users\marcin\scoop\buckets\java\bucket\openjdk11.json
Installed:
C:\Users\marcin\scoop\apps\openjdk11\11.0.2-9
Environment:
JAVA_HOME=C:\Users\marcin\scoop\apps\openjdk11\current
PATH=%PATH%;C:\Users\marcin\scoop\apps\openjdk11\11.0.2-9\bin
```bash
$ scoop info openjdk13
Name: openjdk13
Description: Official production-ready open-source builds of OpenJDK 13
Version: 13.0.2-8
Website: https://jdk.java.net/13
License: GPL-2.0-only WITH Classpath-exception-2.0 (https://spdx.org/licenses/GPL-2.0-only WITH Classpath-exception-2.0.html)
Manifest:
C:\Users\marcin\scoop\bucketsjava\bucketopenjdk13.json
Installed:
C:\Users\marcin\scoop\appsopenjdk13\13.0.2-8
Environment:
JAVA_HOME=C:\Users\marcin\scoop\appsopenjdk11\current
PATH=%PATH%;C:\Users\marcin\scoop\appsopenjdk13\13.0.2-8\bin
The current `java` is `openjdk11` in my case
```bash
$ scoop which java
C:\Users\marcin\scoop\apps\openjdk11\current\bin\java.exe
Now I want to switch to openjdk13 by using scoop reset command (as mentioned in the guide)
$ scoop reset openjdk13
Resetting openjdk13 (13.0.2-8).
Linking ~\scoop\apps\openjdk13\current => ~\scoop\apps\openjdk13\13.0.2-8
The command ends with success. However, the java version is not switched. It is still locked at openjdk11:
$ scoop which java
C:\Users\marcin\scoop\apps\openjdk11\current\bin\java.exe
A quick investigation revealed two java executables on the %PATH%
$ where java
C:\Users\marcin\scoop\apps\openjdk11\current\bin\java.exe
C:\Users\marcin\scoop\apps\openjdk13\current\bin\java.exe
So the shell will always take the first one available, openjdk11 in my case.
Is the the scoop reset command broken ATM? Or, maybe I misunderstood the scoop reset command?
My scoop version is
$ scoop -v
Current Scoop version:
a9fa775d (HEAD -> master, origin/master, origin/HEAD) chore(buckets.json): Update scoop-nonportable URL (#3776)
'extras' bucket:
8c1326b0 (HEAD -> master, origin/master, origin/HEAD) postman: Update to version 7.16.0
'giantswarm' bucket:
47b39b1 (HEAD -> master, origin/master, origin/HEAD) Update gsctl to 0.18.1
'java' bucket:
6a6b346 (HEAD -> master, origin/master, origin/HEAD) adopt8-openj9-nightly: Update to version 202001161141
'jetbrains' bucket:
30fbf9f (HEAD -> master, origin/master, origin/HEAD) WebStorm-EAP: Update to version 2019.3.2-193.6015.20
'main' bucket:
8139a381 (HEAD -> master, origin/master, origin/HEAD) jfrog: Update to version 1.33.1
'nonportable' bucket:
0377c8a (HEAD -> master, origin/master, origin/HEAD) virtualbox52-np: Update to version 5.2.36
'versions' bucket:
87b59aa (HEAD -> master, origin/master, origin/HEAD) rclone-beta: Update to version 1.50.2-139-g1ba5e991
Does restarting console solve this problem?
No, it does not. I forgot to mention it.
me too,
I find the problem only preduce in the situation of "install with global".
I think the problem is, that openjdk11 and openjdk13 are different packages and therefore you can't switch the version with openjdk@<version> as openjdk in this context is a completely different package to scoop. You'd have to install openjdk, but the problem with this approach is, that the openjdk package - or rather its scoop manifest file - only contains the most recent version, which is currently 14. This is a bug in my opinion and should be addressed.
My current workaround is to execute
[Environment]::setEnvironmentVariable("JAVA_HOME", "$home\scoop\apps\<JDK>\current\", "User") (PowerShell) when you want to change the java version. Of course you need to change the part saying <JDK> to whatever JDK installation you have. In your example this would be openjdk11 or openjdk13. You can use this PowerShell script. Just add it to a directory included in your path variable.
Also, you need to add %JAVA_HOME%bin to the very beginning of your path variable, because every time you install a new java version, it gets added to the very beginning of your path variable and also because just changing the directory to where JAVA_HOME points to doesn't change which java executable gets called, since this is only determined by your path variable's order (the first executable in your path with the specified name is always the one, which gets executed).
Note: If you installed scoop in a different directory, than the default, you'd need to use the SCOOP environment variable instead of $home\scoop (I might be wrong with the existence of the SCOOP variable so correct me if I'm wrong, but then again you might just add it yourself).
I believe this is because scoop reset doesn't reorder PATH directories added by "env_add_path", only recreates shims and environment variables (although I haven't checked that this is the case).
This will probably be solved if both openjdk packages will list java.exe under "bin" instead of using "env_add_path".
@Smail Yes, this is exactly the reason you wrote.
_I think the problem is, that
openjdk11andopenjdk13are different packages and therefore you can't switch the version withopenjdk@<version>asopenjdkin this context is a completely different package to scoop._
The documentation about switching Java versions is misleading because it says the opposite as it should work as intended 🤷♂️.
+1 from my side, just got confused by the documentation
There is a corretto, a corretto8 and a corretto11 package. To make it work with reset we would need both version in one package, right?
I use corretto, sapmachine and openjdk and would like to switch from one to another using scoop reset
the best would be to have the path reordered when using reset to targeted jdk !
Currently I have a generic java folder in the path and use a junction to switch from one to another folder but this less flexible than a per console solution.
Currently I have a generic java folder in the path and use a junction to switch from one to another folder but this less flexible than a per console solution.
Pretty cool solution. I think it should be integrated into Scoop core.
Define "platforms", like python, ruby, java, Add platform bin into PATH and than switch platform bin into real installation via directory junction (symlink seem require elevation).
The benefit of solution - it is only few IO calls to FS, no need to restart apps to pick up updated PATH, will work from CMD.exe, Cygwin, WSL!
Command for managing platforms might emit helpers for CMD/WSL/Cygwin for other env vars (like JAVA_HOME), examples ready to be inserted into shell:
CMD: set JAVA_HOME=%SCOOP%\apps\openjdk15\current
WSL: export JAVA_HOME=/mnt/c/opt/scoop/apps/openjdk15/current
Cygwin: export JAVA_HOME=/cygdrive/c/opt/scoop/apps/openjdk15/current
I think that JAVA_HOME / GRAALVM_HOME can point to "Java platform" folder switchable via junction to latest Java too.
Most helpful comment
I use corretto, sapmachine and openjdk and would like to switch from one to another using scoop reset.
the best would be to have the path reordered when using reset to targeted jdk !
Currently I have a generic java folder in the path and use a junction to switch from one to another folder but this less flexible than a per console solution.