Jswap allows you to quickly download and switch between different versions of the Java JDK via the command line. It works on Windows, Linux and macOS and does not require admin permissions.
Jswap uses the the Adoptium API to download the Eclipse Temurin distribution of OpenJDK.
Prebuilt binaries for Windows, Linux and macOS can be downloaded from the Releases page.
- Download the tar.gz archive for your OS and architecture, then extract the archive you just downloaded into a folder that is in your PATH, such as
/usr/local/bin
or~/.local/bin
. - Append the following lines to the
.bashrc
file in your home directory (or.zshrc
file if you are using zsh):export JAVA_HOME=~/.jswap/current-jdk export PATH=$JAVA_HOME/bin:$PATH
Simply download and run the .exe installer. This will set (and eventually override) the JAVA_HOME
environment variable for te current user and add jswap
, java
and javac
to the current user PATH.
Jswap can then be easily uninstalled from the "Add/Remove Programs" section in the Windows Control Panel.
Alternatively, if you have Bash installed on Windows, you can install Jswap in the same way you would install it on Linux or macOS. The only difference is that the Jswap Windows executable stores data in the LocalAppData folder rather than the home directory.
This will make Jswap available only in the Bash shell and will not touch the Windows environment variables.
- Download the zip archive for Windows and extract it into a folder that is in your PATH, or into a new folder and then add it to you PATH.
- Append the following lines to the
.bashrc
file in your home directory (create the file if it does not exists):export JAVA_HOME=$LOCALAPPDATA/Jswap/current-jdk export PATH=$JAVA_HOME/bin:$PATH
Download and install the latest available release of a given JDK major:
jswap get 21
Modify PATH and JAVA_HOME to use the latest installed release of a given major:
jswap set 21
List all the installed JDKs:
jswap ls
Run jswap --help
for more information.
To build the Jswap executable from sources you need the following dependencies:
- Go
- Make
- Git
To build Jswap for your OS and architecture run this:
make
You can also target different platforms:
make linux-amd64 # Linux x64
make win-amd64 # Windows x64
make mac-amd64 # macOS with Intel CPU
make mac-arm64 # macOS with ARM CPU
The executables will be found in the build
directory.
To build the Windows installer you need NSIS and the EnVar plugin for NSIS.
NSIS is also available on Linux and can be easily installed via apt on Ubuntu and Debian:
sudo apt install nsis
Place the EnVar plugin dll files in /usr/share/nsis/Plugins
.
Run the following command to build the Jswap Windows installer:
make win-installer
You can build Jswap and the Windows installer for any supported platform using Docker, without any other dependency.
First, build the jswap-builder
Docker image:
docker build -t jswap-builder .
Run the following command to create a Docker container that builds Jswap and the Windows installer for all the supported platforms from the sources in the current directory:
docker run -v $PWD:/app --name jswap-builder jswap-builder
The jswap-builder
image runs the Make target all
by default. If you want to run a different Make target you can pass it as a command to docker run
. For example, if you want to build only the Windows installer run this:
docker run -v $PWD:/app --name jswap-builder jswap-builder win-installer
For subsequent builds you can reuse the previously created container to improve build times:
docker start -a jswap-builder