I've build my own lighttpd .deb package and I do not want to upgrade it using the apt-get command. Also, I do not want to upgrade a few more packages such as php5-cgi, httpd and so on. How do I blacklist a package or packages so that when I run apt-get upgrade, it will ignore blacklisted packages and install the rest of updates under Debian or Ubuntu Linux server system?
| Tutorial details | |
|---|---|
| Difficulty | Intermediate (rss) |
| Root privileges | Yes |
| Requirements | dpkg |
You need use the dpkg command - a tool to install, build, remove and manage Debian packages. Each package under Debian or Ubuntu Linux has the following selection stats:
- install - The package is selected for installation.
- hold - A package marked to be on hold is not handled by dpkg, unless forced to do that with option --force-hold.
- deinstall - The package is selected for deinstallation (i.e. we want to remove all files, except configuration files).
- purge - The package is selected to be purged (i.e. we want to remove everything from system directories, even configuration files).
Option #1: dpkg command syntax
To blacklist a Debian / Ubuntu package use the following command:
echo "packageName hold" | dpkg --set-selections echo "lighttpd hold" | dpkg --set-selections
To remove package hold and install/upgrade again:
echo "packageName install” | dpkg --set-selections echo "lighttpd install” | dpkg --set-selections
Option #2: /etc/apt/apt.conf.d/01autoremove
Another option is to edit a file called /etc/apt/apt.conf.d/01autoremove, enter:
# vi /etc/apt/apt.conf.d/01autoremove
Sample outputs:
APT
{
NeverAutoRemove
{
"^firmware-linux.*";
"^linux-firmware$";
"^linux-image.*";
"^kfreebsd-image.*";
"^linux-restricted-modules.*";
"^linux-ubuntu-modules-.*";
};
Never-MarkAuto-Sections
{
"metapackages";
"restricted/metapackages";
"universe/metapackages";
"multiverse/metapackages";
"oldlibs";
"restricted/oldlibs";
"universe/oldlibs";
"multiverse/oldlibs";
};
};Move cursor at the the bottom of the section called "Never-MarkAuto-Sections" and append and entry to the section to block grub I entered "php5-cgi*":
Never-MarkAuto-Sections
{
"metapackages";
"restricted/metapackages";
"universe/metapackages";
"multiverse/metapackages";
"oldlibs";
"restricted/oldlibs";
"universe/oldlibs";
"multiverse/oldlibs";
"php5-cgi*";
};
Save and close the file.
A note about RHEL / CentOS / SL / Fedora Linux users
You need to edit a file called name.repo see, how to blacklist a package under RHEL / CentOS for more information.
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop











![Error While Loading Shared Libraries: libgobject-2.0.so.0 Error and Solution [ Debian / Ubuntu ]](http://s13.cyberciti.org/images/shared/rp/3/13.jpg)

{ 3 comments… read them below or add one }
There’s another way to do this under Ubuntu and Debian which I like as I’m quite lazy.
You have to install a package called wajig, but it’s small and doesn’t interfere.
sudo apt-get install wajig
and then can just do :
sudo wajig hold packagename
wajig can do lots of other things too, but I haven’t investigated them yet.
Another option is to use equivs and add all those packages that you never want to see installed into its Conflicts: list.
Hi,
I suggest to use apt pinning to blacklist packages or set certain versions of a package on hold.
wiki.debian.org
debian-handbook.info