For example:

The following command will install all packages that match it's pattern:

  sudo apt-get install k3b-*

If I want to use that instruction but don't want to install one specific package with broken dependencies, how do I do that?

I have tried this but not works.

sudo apt-get install "$(apt-cache --no-generate pkgnames k3b | grep -v extrathemes | tr '\n' ' ')" :

 sam@/home/sam/code/ros/ai/cram/roslisp_repl$ sudo apt-get install      "$(apt-cache --no-generate pkgnames k3b | grep -v extrathemes | tr '\n' ' ')"
 Reading package lists... Done
 Building dependency tree       
 Reading state information... Done
 E: Unable to locate package k3b-dbg k3b-data k3b 


Thank you~

  • 2
    Sam - I'm confused - you've marked the question as solved but have edited the question saying otherwise... is the question solved or not - please update as appropriate. – fossfreedom Sep 18 '11 at 10:26
  • Yes,enzotib's answer is solved my question with 2 steps. But con-f-use's answer is trying to solve my question with another way(1 step) but with errors. I want to learn more so I revise my origin post to let @con-f-use know what I am tring. – sam Sep 18 '11 at 10:39
  • You should remove double quotes around $(instructions). – enzotib Sep 18 '11 at 10:46
  • Won't sudo apt-get install k3b-* fail if there is a file that matches the pattern in the current directory? – svick Sep 18 '11 at 17:37
  • I haven't happened this situation,and I solve it in second way by removing "" quote. – sam Sep 18 '11 at 23:14

You can do

list=$(apt-cache --names-only search ^k3b-* | awk '{ print $1 }' | \
    grep -v bad-pkg)
sudo apt-get install $list

Say you don't want to install the k3b-extrathemes package. There might be no practical way to do this but to list all the packages except for the one: sudo apt-get install k3b-data k3b-dbg.

However you can do that with some aid:

sudo apt-get install $(apt-cache --no-generate pkgnames k3b \
    | grep -v extrathemes | tr '\n' ' ')

That's not terribly partical. apt-cache ... returns the name of the packages, grep -v PACKAGENAME excludes the packages and the tr command replaces new lines by spaces.

  • I have revised my origin post for this instruction's result.Why can't locate packages? – sam Sep 18 '11 at 10:13
  • You should remove double quotes around $(instructions). – enzotib Sep 18 '11 at 10:47

I discovered a much simpler way of doing this:

sudo aptitude install <package>

This will use aptitude instead of apt-get - which provides you with more options. When you see something like the following:

The following NEW packages will be installed:
0 packages upgraded, 12 newly installed, 0 to remove and 0 not upgraded.
Need to get 130 MB/130 MB of archives. After unpacking 216 MB will be used.
Do you want to continue? [Y/n/?]

Instead of pressing 'y', type the following:


That's a '-' followed by the name of the package to skip. Then you can proceed with the installation as per normal.

  • 1
    Newer releases don't install aptitude by default, but you can easily install it using sudo apt-get install aptitude or from the Software Center. – Mechanical snail Jan 18 '13 at 6:08

You can trivially do this with apt; if you want to install foo but not bar, do this:

sudo apt install foo bar-

i.e. append a hyphen to bar. From the apt-get man page:

If a hyphen is appended to the package name (with no intervening space), the identified package will be removed if it is installed. Similarly a plus sign can be used to designate a package to install.

This apparently works for packages that would be installed, as well as those that are already installed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.