Skip to content

Instantly share code, notes, and snippets.

@spencermathews
Last active March 23, 2016 09:51
Show Gist options
  • Save spencermathews/3613b72e330c6eaff558 to your computer and use it in GitHub Desktop.
Save spencermathews/3613b72e330c6eaff558 to your computer and use it in GitHub Desktop.
How to back stuff up

Quick reference for backing up and restoring installed packages.

  • Homebrew
  • Python
  • R
  • Ruby

Homebrew

Dump installed packages and cask to a Brewfile homebrew-bundle (aka Brewdler/Brew Bundler) which replaces the deprecated brew bundle command:

brew bundle dump

Check a Brewfile against what is currently installed:

brew bundle check

Install dependencies from Brewfile in the current directory:

brew bundle

Show all Homebrew formulae not listed in Brewfile (use --force to uninstall them):

brew bundle cleanup

Python

Anaconda

Export conda and pip packages from a conda environment (note: environments with conda env list):

conda env export -n root > environment.yml  # or other conda environment

Note: conda list -e also outputs requirement strings, and these explicit spec files seem identical except they do not include pip packages. For some reason they are not usually cross-platform and indicate the platform in a comment. Also possible difference in how they handle channels?

Create environment (may need to specify name):

conda env create -f environment.yml

Pip

Create requirements file:

pip freeze > requirements.txt`

Install packages from the file:

pip install -r requirements.txt

See also: pip list, yolk

R

Backup package list:

packages <- installed.packages()[,"Package"]
save(packages, file="Rpackages.RData")

Install packages from list:

load(file_name, verbose=TRUE)
for (p in setdiff(packages, installed.packages()[,"Package"]))  install.packages(p)

TODO: save as plain text

Ruby

Gem

List local gems:

gem list [--no-versions]

Display detailed information with -d, --details flags.

List which other gems a gem depends on:

gem dependency [--reverse-dependencies]

Bundler

Bundler is a useful tool for tracking gems and their versions. How does this work? I vaguely recall hearing about Gemfile support in gem itself, but I couldn't find the reference...

For fun you can get a dependency graph from Bundler/Gemfile (requires graphviz):

gem install ruby-graphviz bundle viz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment