Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've noticed that the majority of Ubuntu help websites present apt commands in the following format:

sudo add-apt-repository ppa:[ppa-address]
sudo apt-get update
sudo apt-get install [application-name]

But I know that apt commands like this one work too:

sudo add-apt-repository ppa:[ppa-address] && sudo apt-get update && sudo apt-get install [application-name]

Is there a particular reason that most sites present in the first format? Are there known issues with chaining commands with &&, or to put it another way are there any benefits/drawbacks to using either method?

Further, other then loss of internet, are there any circumstances in which an apt command might fail?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

Personally, I think sites list them one by one just for clarity. It's easier to run one at a time and understand what it does then it is to run, say 3, all at once.

I might point out too, not all sites do list commands one by one. For example, in the OMG Ubuntu article on installing Unity Tweak Tool the commands are listed as:

sudo add-apt-repository ppa:freyja-dev/unity-tweak-tool-daily  
sudo apt-get update && sudo apt-get install unity-tweak-tool  

It's also worth noting that && will only run the second or third (etc) command if the command before it returns exit status 0. In other words, the command after && will only be run if the command before && completes successfully.

If you'd like your string of commands to execute one by one no matter if any fail you would separate each command with ; instead of &&. For example:

sudo add-apt-repository ppa:[ppa-address] ; sudo apt-get update ; sudo apt-get install [application-name]  

(Of course, this wouldn't be a good thing to do when installing packages!)

There are a number of reasons why an apt command would fail:

  • apt-get install could fail for quite a few reasons, among them dependency issues, not enough disk space, no internet connection, or an old or malformed sources.list file.

  • apt-get update could fail for similar reasons, a malformed sources.list, no internet connection, a 404 PPA, etc.

These are just some of the things that would cause apt to fail, causing commands after && to not be run.

share|improve this answer

It's presented in the first form because it's easier to read.

Plus, if you need to review your history for one of the commands, it's easier than picking one part of a long, complex command.

share|improve this answer
Another reason: it is easier to edit if you made a mistake. –  Lekensteyn May 9 '13 at 21:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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