2 Replies - 490 Views - Last Post: 07 November 2016 - 09:13 AM

#1 mercy_angel  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 330
  • Joined: 28-February 13

apt-get update and install in one command line

Posted 07 November 2016 - 08:26 AM

Does it possible to do it?
Is This A Good Question/Topic? 0
  • +

Replies To: apt-get update and install in one command line

#2 Atli  Icon User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4238
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: apt-get update and install in one command line

Posted 07 November 2016 - 09:09 AM

You can chain commands in various ways.

You can simply use the semi-colon (;) between commands, and they will execute sequentially:
$ sudo apt-get update; sudo apt-get install git



You can also use various operators instead of the semi-colon, to alter the behavior of the sequence. The most commonly used operator is undoubtedly the AND operator (&&) which ensures that the first command executes successfully before moving onto the next one, or else stops.
$ sudo apt-get update && sudo apt-get install git


Now, the install won't happen if the update fails.
Was This Post Helpful? 1
  • +
  • -

#3 no2pencil  Icon User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6559
  • View blog
  • Posts: 30,699
  • Joined: 10-May 07

Re: apt-get update and install in one command line

Posted 07 November 2016 - 09:13 AM

Keep in mind that the first sudo has a "timeout" for credentials. So if the first command is successful, but takes like 15 minutes, you will be prompted for sudo privileges again on the second command. This also assumes that your setup requires you to type your password for sudo. A side-step to that would be to sudo to root, become the root user, & then you are not required to use the sudo command to elevate privileges for your package manager.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1