Truly non-interactive / unattended apt-get install

You may also like...

15 Responses

  1. jnachbar says:

    If you are using sudo to run apt-get, you will need to tell sudo to pass the environment variable. You can use the -E flag to sudo (which exports everything, which may be a security hole), or the env_keep option in the sudo configuration, as described here: http://stackoverflow.com/questions/8633461/how-to-keep-environment-variables-when-using-sudo

  2. Andy says:

    Whoever is interested in debconf preconfiguration, here’s how to do:

    sudo debconf-set-selections <<< 'mysql-server- mysql-server/root_password password your_password’
    sudo debconf-set-selections <<< 'mysql-server- mysql-server/root_password_again password your_password’
    sudo apt-get -y install mysql-server

    The only drawback is once you’ve setup your scripts with the proper version number and there’s a newer mysql-server this preconfiguration will not work anymore. I prefer the method described here using noninteractive setup and changing the root password afterwards.

    • Andy says:

      Oops …. let’s try again:

      sudo debconf-set-selections <<< ‘mysql-server-<version> mysql-server/root_password password your_password’
      sudo debconf-set-selections <<< ‘mysql-server-<version> mysql-server/root_password_again password your_password’
      sudo apt-get -y install mysql-server

  3. sirvon says:

    yes it is!! thanks the comments were especially helpful!

  4. Pedro says:

    Ha, 4 years later and your post is still useful. Thanks!

  5. PhilT says:

    You can use debconf to preconfigure things required by apt.

  6. Michael says:

    Please note that this method may be affected by /etc/sudoers settings (reset_env), subprocesses that do not read shell dot files and so on. You can configure apt (man 5 apt.conf) to assume “yes” by default, see https://github.com/travis-ci/travis-cookbooks/commit/22a33eb345f797187f59df9c11861a21f0e9567d for example

  7. Mukul says:

    Awesome Info ! ! !

    Saved me soo much timeee !!!

    Did not think environment variable would come to the rescue :)

  8. Ronna says:

    Any idea how to do it in Ubuntu?

    • Jon says:

      Define “do it in Ubuntu” because when I did the above post, it was in Ubuntu.

      If you mean, do this on a desktop machine… that’s a different story. In that case you’d either need to install one machine and capture the image with something like clonezilla. Then redeploy that to all your other machines. OR, if they are different, you’d have to modify the Ubuntu installer to fetch your post install script. You might want to check out: https://help.ubuntu.com/community/InstallCDCustomization — Specifically the portion about preseeing.

      Good luck!

  9. lamby says:

    You can preconfigure the passwords using debconf preseeding.

  10. Mike says:

    So how would you provide a preconfigured password to this mysql installation?

    • Jon says:

      I don’t know how to provide the password to the setup, but you could add a line afterwards to set the password (since it is blank by default). The following line will do that:

      mysqladmin -u root password NEWPASSWORD

  1. 2011-12-07

    […] I was wondering about how to do a non-interactive installation of MySQL using apt-get, because it prompts for the root password. I found my answer in an article — Truly non-interactive / unattended apt-get install. […]

Leave your thoughts

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: