---
# System prepended metadata

title: Setting Java and Switching Version on Ubuntu
tags: [' Java', note]

---

---
title: Setting Java and Switching Version on Ubuntu
tags: note, Java
---

# Setting Java and Switching Version on Ubuntu

1. Search for openJDK
```bash=
apt-cache search openjdk
```

2. Choose desired version and install (`hdeadless` for non-gui Java applications)
```bash=
apt-get install openjdk-8-jdk-headless
```

2. Check if successful
```bash=
java -version
```

3. Repeat above step to install other java version

5. List valid versions
```bash=
update-java-alternatives --list
```

4. Set to version
```bash=
update-java-alternatives --set /path/to/java
```

5. Check if successful
```bash=
java -version
```