Skip to Content

Terminal Tips: Install software updates from the command line


Sure, you could update your Apple software by opening Software Update from the Apple menu. But what if you're inclined to use a command line interface, or maybe you need to update a remote machine via SSH? There's a way to complete a software update in Terminal.app. Here's how.

If you want to do an automatic install of all the updates for your particular Mac, first log in as an administrative user. Then open Terminal.app (located in /Applications/Utilities), and type (or copy/paste) the following command:
sudo softwareupdate -i -a

and hit Return. Next, you'll be prompted to enter your password; do so, and then hit Return. The application will then look for available updates, download them, and then install them. You will see the progress in Terminal. If no updates are available, Terminal will let you know.

This command replicates the functionality of the normal Software Update utility. However, you can use it on other machines in the background via SSH remote login, or you could apply a specific update rather than the full list of available patches. To see all the command options, type man softwareupdate at the Terminal prompt.

Want more tips and tricks like this? Visit TUAW's Terminal Tips section!

Categories

Terminal Tips

Sure, you could update your Apple software by opening Software Update from the Apple menu. But what if you're inclined to use a command...
 

Add a Comment

*0 / 3000 Character Maximum

13 Comments

Filter by:
Dr. ScottyB

This + 'dsh' is a godsend on a cluster....

December 02 2008 at 11:54 PM Report abuse rate up rate down Reply
WPT

There is a man page for softwareupdate. This describes additional options, such as selecting specific updates and ignoring others. With awk and a shell script, or perhaps an applescript, you could be very specific about which updates to install in the middle of the night when you're asleep.

December 02 2008 at 7:47 PM Report abuse rate up rate down Reply
raff

Nice! And it saved me from having to restart my computer (that just restarted this morning) just to update iTunes and Safari.

December 02 2008 at 3:00 PM Report abuse rate up rate down Reply
Doug

If you want to reboot after installing, just try the following:

sudo softwareupdate -i -a;reboot

December 02 2008 at 2:01 PM Report abuse rate up rate down Reply
WillGonz

I just updated 50 Macs with this command using Remote Desktop. Here is what you do.
Select your Macs in the list.
Click Unix
Enter in softwareupdate -i -a
Make the login user as root.

Then set back and relax. I have been waiting for this tip and it has just saved me hours as a system admin.

Thanks TUAW!!!

WillGonz

December 02 2008 at 12:18 PM Report abuse rate up rate down Reply
TjL

I believe there is also the advantage of not having to click through all the EULAs (if any) but I couldn't say for sure.

You can also use this via cron, to run your updates overnight, rather than randomly interrupting you during the day.

Just some reasons why.

December 02 2008 at 12:18 PM Report abuse rate up rate down Reply
bbarrera

Some updates will pop-up a license agreement, to prevent that set the shell environment variable "command_line_install" to 1, for example:

export command_line_install=1

before running the softwareupdate command. You can read about this in Apple's Command Line documentation for Tiger Server or Leopard Server.

You can avoid piping the administrator's password by adding the following line to /etc/sudoers (using visudo command):

Administrator ALL=PASSWD:ALL, NOPASSWD: /usr/sbin/softwareupdate, /sbin/reboot, /usr/bin/pmset

(assumes Administrator is the user that runs softwareupdate and reboot commands)

I've created a shell script "SUinstall" that handles all the tasks:

#!/bin/bash

export COMMAND_LINE_INSTALL=1
sudo /usr/sbin/softwareupdate -i -a
sudo /sbin/reboot

So I run "ssh adminstrator@remoteHost SUinstall" to install updates and reboot on the remote computer named "remoteHost"

December 02 2008 at 12:15 PM Report abuse rate up rate down Reply
ACLetras

StPaddy, this is one of the included template Unix commands in ARD (under Miscellaneous). You have the option to list updates that are available, just download them or download and install.

December 02 2008 at 12:10 PM Report abuse rate up rate down Reply
Chuck

The GUI version of Software Update couldn't sucessfully install the latest security update. I just tried the update from within Terminal as described above and the update installed sucessfully.

Thanks for the tip.

December 02 2008 at 11:59 AM Report abuse rate up rate down Reply
JKT

This is indeed a handy command--I just tried it using ARD and it works fine as long as you do the old trick of piping the root password into sudo.

The only bummer is that there doesn't seem to be a switch in the command for rebooting when it's complete.

December 02 2008 at 11:41 AM Report abuse rate up rate down Reply
Buy an ad here

Hot Apps on TUAW

Tweets

© 2012 AOL Inc. All Rights Reserved.