A Shell Script to Update your Package Managers

Update Package Manager

Ok so I forget to update my package managers all the time – and I made a mess of some dependencies. So I put a stop to it by writing this shell script.

First off I started out just having iTerm do it automatically by giving the commands to update on start. This was pretty long winded and I didn’t want all that going off every time I opened up my terminal to do some work, which is getting to be all the time now.

So what I needed was something to remind me to update and not automatically do it every time.

This is how it looks when I open up iTerm now.

iTerm 2 Example
Yes iTerm. I want to update my shit.

How To

This is for Mac (you could do something similar on Linux), my set up isn’t too complicated I use Oh-my-Zsh for ease (it’s super useful, and pretty) and iTerm2 because regular terminal is boring.

Robby Russel’s Oh-my-Zsh


You don’t need either of these for what I’m going to show you but well, you should take a look at them if you’re not using them already.

cd /bin
 note: It would probably make more sense to put this in /usr/local/bin

Create a new file here, no .txt extension with your preferred text editor. If you use emacs or vim you’re probably not going to be reading this tutorial so we’ll assume nano. Name this file whatever you want to update command to be. Mine is ‘update_pkgs’.

sudo nano update_pkgs

 and then write out something like this:
echo "Do you want to update your package managers? (Y/n)"
 read ANSWER
if [ "$ANSWER" == "y" ]
 echo "******Updating npm*******"
 npm update
 echo "******Updating Ruby Gems*******"
 sudo gem update
 echo "******Updating Homebrew*******"
 brew update
 echo "================ DONE ================="
 echo "Not Updated..."

 The #!/bin/sh denotes the language.

Then there’s a Y/n question. Yes I’d like to update my packages. Or No, I’m busy and I don’t want to mess with those files right now.

Then an if statement, if you answer Y it will go ahead and update your chosen package managers, and echo out what it’s doing as it goes, with an finish message at the end.

You could even put an ascii cat in at the end.

( o.o )

Save that out. Now set the permissions with

sudo chmod +x update_pkgs(or whatever you named the file)

So to get this to run when you open your terminal, if you’re using iTerm, open your user profiles with cmd+o and where it says “send text at start” enter in ‘update_pkgs’ or whatever your command is called.

No iTerm? Find your .bash_profile or just .profile and paste in your command, should run it on start.

This is basic stuff, but I didn’t know much about shell scripts before, and really only wanted to do this, and couldn’t find a guide that wasn’t TL;DR.

Credit: Thanks French Beardy Man

  • Hello Lauren

    I recently came across your profile on the page relating to the company Green Tornado within the Network Magazine which I have delivered and then found this website.

    As I’ve now been out of work for several years, I’m now considering a change of career and would like to know more about the possibilities of moving into website design. If possible, please can I ask you the following questions? If you could enclose your reply under each question and return, it would be much appreciated.

    1) Which qualification did you do / need to have to get into website design?

    2) If so, what was the duration of the course and which college?

    3) If I were to study just the following four applications: HTML, CSS, Photoshop and Javascript – would this be sufficient to get me a job in website design or would I need to know about other applications as well?

    4) Apart from Javascript, I don’t want to get too involved in programming. Did you need to study any programming languages?

    5) Does Photoshop allow you to create graphics as well as edit photos?

    6) Is Photoshop the best application to use for creating graphics?

    7) How do the applications Photoshop, Fireworks and Flash all compare?

    8) On the Green Tornado website, which application was used to create the picture of the Wilson’s Corner clock tower?



Leave a Reply

Your email address will not be published. Required fields are marked *