If you just want to install a bunch of packages a simple one-liner could do like:
sudo bash -c 'for package in "tmux" "htop" "gimp"; do apt install -y --no-upgrade "$package"; done'
The loop is not strictly necessary, but without it, if apt fails to find any of the programs in the list, it will fail to install any of the other packages. This can happen for example if you switch to a more recent version of your distro and older packages are not within the repos anymore. If you prefer all or nothing use
sudo apt install -y --no-upgrade tmux htop gimp
If you also want to save your configurations the search term would be "dotfiles". Thats what the configurations in Unix like systems are called since they mostly start with a ".".
A quick and dirty way to save those is just by copying all those configurations directory to your new system. A better way would be to place them under version control with tools like git. I use a combination of git, dotbot and hand written scripts to setup my system.
One point that is missing from the discussion so far is that
apt is typically not the only package management system one needs for anything beyond the bare basics.
Other package management tools might be
cargo and many more.
This is implicitly addressed in the answer by Alex Stragies.
Ansible contains a vast ammount of modules including modules to manage packages apart from
As my answer is focused on write-your-own-script I'd like to expand on that.
A well tested framework such as
Ansible should generally be prefered for most tasks, but self-written code gives an advantage in terms of flexibility in my eyes.
Small example framework
I've written a small code in python which shall examplify how such a framework could look.
with open(os.path.realpath(path)) as f:
for line in f:
match = re.search(r'^(?!\s*$)(?!#)\w+',line)
except Exception as e:
with open(err_log,'w+') as f:
for p in package_list:
print('executing '+command+' '+str(p))
except Exception as e:
args = sys.argv[1:]
package_list = read_package_list(args)
if __name__ == '__main__':
The basic ingredients are a function to process a list of packages separated by newlines (
read_package_list) and a function to execute the installer command in a shell (
Lines with only whitespace and lines starting with
# are ignored when reading in the package list.
main processes the arguments which can be given on the command line as
What does that give me?
Well you can just use any installer command you like
./installerscript.py 'apt install --dry-run' myaptpackages.txt apt_err.log
./installerscript.py 'snap install' mysnaps.txt snap_err.log
./installerscript.py 'pip install --user' mypy.txt py_err.log
./installerscript.py 'git clone' repos.txt git_err.log
This might be helpful if one keeps a list of packages which should all be treated in the same way.
Once such a framework exist it is easy to improve on it.
One could, for example, customize the way the installation process is logged or customize the processing of the command line arguments.
Another aspect is that the script probably shouldn't execute each command as root (if run as root) as it currently does.