65

How can I enable non-free packages on Debian? I want to install Sun's Java JDK but it's not available to me.

Andrew M.
  • 10,982
  • 2
  • 34
  • 29
Quiffner
  • 653
  • 1
  • 5
  • 4

3 Answers3

73

Open up /etc/apt/sources.list, and you should see lines like the following (URLs will likely vary):

deb http://http.us.debian.org/debian stable main contrib

Simply add non-free to the respective URLs you wish to use, i.e.:

 deb http://http.us.debian.org/debian stable main contrib non-free

Running apt-get update will update your local repo with the package listing.

Andrew M.
  • 10,982
  • 2
  • 34
  • 29
31

You can also restrict this a little bit if you only want some very specific packages from non-free (firmwares for your hardware for example).

To do so, keep your /etc/apt/sources.list as described by @Andrew M. Then, use Apt Pinning to disable by default all non-free packages for your current release:

Create a file named /etc/apt/preferences.d/non-free_policy containing the following directives:

Explanation: Disable packages from non-free tree by default
Package: *
Pin: release o=Debian,a=stable,l=Debian,c=non-free
Pin-Priority: -1

Now, create another file for the specific package you want to get from non-free.
Let's assume you want to add the Intel drivers for wireless cards for instance (package firmware-iwlwifi).
Create a file name /etc/apt/preferences.d/firmware-iwlwifi_nonfree with these lines:

Explanation: Enable package firmware-iwlwifi from non-free tree
Package: firmware-iwlwifi
Pin: release o=Debian,a=stable,l=Debian,c=non-free
Pin-Priority: 600

This configuration avoids bloating your package with these annoying non-free packages ;)

jopasserat
  • 411
  • 4
  • 8
  • 4
    More information about apt pinning here: https://wiki.debian.org/AptPreferences – jopasserat Mar 08 '14 at 14:06
  • 1
    What does the `o`, `a`, `l`, and `c` mean in the `Pin:` directive, and how are multiple packages added? – MattBianco Jan 15 '17 at 16:26
  • origin, archive, label and component. check the man page for more details https://manpages.debian.org/jessie/apt/apt_preferences.5.en.html – jopasserat May 03 '17 at 09:59
16

An alternative way to update the package sources configuration file is to use the apt-add-repository command (from the software-properties-common package). If you want non-free package for all sources, run:

sudo apt-add-repository non-free
sudo apt-get update

Answer inspired by: https://askubuntu.com/a/553847/67211

Anthony Geoghegan
  • 2,800
  • 1
  • 23
  • 34
Lucas
  • 261
  • 2
  • 4
  • 1
    This gives me an error of `apt-add-repository: not found` – Chris Stryczynski Sep 27 '19 at 10:34
  • 4
    @ChrisStryczynski, install the optional package `software-properties-common` to get that tool. – Lucas Sep 30 '19 at 10:01
  • DO NOT DO THIS on Linux Mint (perhaps Ubuntu). After rebooting, my cinnamon desktop went missing (in the login screen, there was no option for the Cinnamon desktop) until I did `sudo apt-add-repository non-free -r; apt update; apt upgrade; reboot`. IDK what went wrong or what was going on. – Jack G Jul 06 '20 at 19:06