Debian's package management system categorizes software into different repositories based on licensing. The main ones are:
- main: Fully free software meeting Debian Free Software Guidelines
- contrib: Free software but depends on non-free components
- non-free: Software that doesn't meet DFSG requirements
To install proprietary packages like Sun Java JDK, you need to enable the non-free repository. Here's how:
sudo nano /etc/apt/sources.list
Find lines starting with deb
and add non-free
to them. For example:
deb http://deb.debian.org/debian/ stable main contrib non-free
deb-src http://deb.debian.org/debian/ stable main contrib non-free
After editing, update your package lists:
sudo apt update
With non-free repositories enabled, you can now install the JDK:
sudo apt install sun-java6-jdk
Note: The exact package name might vary depending on your Debian version. For newer versions, you might need:
sudo apt install oracle-java8-jdk
Check if Java is properly installed:
java -version
javac -version
If you prefer not to modify sources.list
directly, you can use:
sudo add-apt-repository "deb http://archive.canonical.com/ubuntu $(lsb_release -sc) partner"
sudo apt update
sudo apt install sun-java6-jdk
If you have multiple Java versions installed, set the default:
sudo update-alternatives --config java
sudo update-alternatives --config javac
If you encounter "Package not found" errors:
- Ensure you've run
sudo apt update
- Check your Debian version codename matches the repository
- Verify the package exists in the non-free repository
Debian maintains strict policies about software freedom, which is why its default repositories are divided into:
main - DFSG-compliant packages (free software) contrib - DFSG-compliant but depend on non-free software non-free - Non-DFSG-compliant packages
To enable non-free repositories, you'll need to edit your /etc/apt/sources.list
file. Here's how to do it properly:
sudo nano /etc/apt/sources.list
Look for lines starting with deb http://
and add non-free
to each relevant line. For example:
deb http://deb.debian.org/debian/ bullseye main contrib non-free deb-src http://deb.debian.org/debian/ bullseye main contrib non-free deb http://security.debian.org/debian-security bullseye-security main contrib non-free deb-src http://security.debian.org/debian-security bullseye-security main contrib non-free
For newer Debian versions, you can use this command to enable non-free repos:
sudo apt-add-repository non-free sudo apt update
Once non-free repos are enabled, install the JDK with these commands:
sudo apt update sudo apt install default-jdk
For Oracle's official JDK (when available in non-free):
sudo apt install oracle-java17-jdk
Check your Java version to confirm success:
java -version javac -version
If you encounter dependency problems, try:
sudo apt --fix-broken install sudo apt autoremove
For systems with multiple Java versions, use update-alternatives
:
sudo update-alternatives --config java
To permanently keep non-free enabled, create this configuration file:
sudo tee /etc/apt/apt.conf.d/90non-free <