Does anyone know how to write a shell script to install a list of applications? It's a pain to have to install each application by hand every time I set up a new system.

Edit: It still asks me Do you want to continue [Y/n]?. Is there a way to have the script input y or for it not to prompt for input?

  • 2
    There used to be a program called 'yes' that did just that. (It wrote 'y' continuously to STDOUT.) – Nathan Osman Jul 31 '10 at 0:05

I would assume the script would look something like this:

apt-get update  # To get the latest package lists
apt-get install <package name> -y

Just save that as something like install_my_apps.sh, change the file's properties to make it executable, and run it from the command line as root.

(Edit: The -y tells apt-get not to prompt you and just get on with installing)

  • How to make it executable? I assume i would run it like: sudo ./install_my_apps.sh – jumpnett Jul 30 '10 at 19:22
  • I'm not certain whether it's necessary to make it executable (I'm a Python guy; not much into BASH). But if you must, it can be made executable with chmod +x ./install_my_apps.sh. – Michael Crenshaw Jul 30 '10 at 19:40
  • Or right click on it, select "Properties". In the window that opens go to the "Permissions" tab, and check the checkbox that says "Allow executing file as a program" – jfoucher Jul 30 '10 at 20:08
  • 6
    I don't know why this is CW, but I edited it anyway to put the -y flag. Note: If you want to make it look clearer, you can use --yes or --assume-yes in place of -y. – Umang Aug 1 '10 at 5:20

Well, according to your question the easiest script would be:

LIST_OF_APPS="a b c d e"

aptitude update
aptitude install -y $LIST_OF_APPS

However you could also enter aptitude update && aptitude install -y a b c d e. So maybe your question is missing the crucial point here. If there are some further requirements it would be nice to explain them.

  • 1
    Note that apt-get would work as a drop-in replacement for aptitude here, if that is your preference. Simply replace both instances of "aptitude" with "apt-get". – Michael Crenshaw Jul 30 '10 at 18:50

Just create a list of apps in a file, example.list, and run

cat example.list | xargs sudo apt-get -y install
  • this is awesome. never knew how to feed a list of packages into apt before! – Thufir Aug 18 '17 at 7:34
  • xargs feeds the piped lines into any command, by simply appending them as arguments – Xerus May 11 '18 at 20:42

I would opt for the following script: vim install

apt-get update  # To get the latest package lists
apt-get install $1 -y

Then I should make the above script executable chmod +x install. Then to use it, I could type: ./install <package_name>. Example: ./install clang

  • 1
    I wanted all the programs listed in the file. With this method, I would still have to input the name of the program as a command line argument, so there really isn't a benefit. – jumpnett Sep 13 '12 at 19:11
  • 1
    @jumpnett Lol, I missed the list point. I am starting to lack caffeine and it shows. Sorry for it. May update the answer. – NlightNFotis Sep 13 '12 at 19:23
  • Plus it's going to run update for every program to install, time-consuming. And it needs sudo. – Gauthier Apr 24 '15 at 10:50
  • this is extremely unneccessary. You might as well put alias install='sudo apt-get install -y' into your .bash_aliases – Xerus May 11 '18 at 20:41

set -eu -o pipefail # fail on error , debug all lines

sudo -n true
test $? -eq 0 || exit 1 "you should have sudo priveledge to run this script"

echo installing the must-have pre-requisites
while read -r p ; do sudo apt-get install -y $p ; done < <(cat << "EOF"
    zip unzip

echo installing the nice-to-have pre-requisites
echo you have 5 seconds to proceed ...
echo or
echo hit Ctrl+C to quit
echo -e "\n"
sleep 6

sudo apt-get install -y tig
  • 1
    add explanations please and fix all these typos – Xerus May 11 '18 at 20:40
  • which line in your opinion needs explanation ?! – Yordan Georgiev May 13 '18 at 16:41

I made a script for this.
Check http://github.com/dinukasal/install

you can add packages too

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.