1

I'm attempting to automate deployment of my different machines by scripting installation of emacs and emacs packages. While I realize that I can set up my .emacs file to automatically install packages if they're not found, I'd rather have these packages pre-installed.

I'm executing elisp from the command line like this:

/usr/local/bin/emacs --batch --eval "(progn (package-initialize) (package-refresh-contents) (mapc 'package-install '(powerline airline-themes doom-themes sr-speedbar)))"

If all of the packages are currently installed, it works fine:

Importing package-keyring.gpg...
Importing package-keyring.gpg...done
Contacting host: elpa.gnu.org:443
Package refresh done
Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations
Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations
‘powerline’ is already installed
‘airline-themes’ is already installed
‘doom-themes’ is already installed
‘sr-speedbar’ is already installed

But, if one of the packages is not installed, it can't install the package and ends up saying it can't find a version of the package with a - appended to it (i.e. sr-speedbar becomes sr-speedbar-):

Importing package-keyring.gpg...
Importing package-keyring.gpg...done
Contacting host: elpa.gnu.org:443
Package refresh done
Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations
Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations
‘powerline’ is already installed
‘airline-themes’ is already installed
‘doom-themes’ is already installed
Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations
Package ‘sr-speedbar-’ is unavailable

When I paste the code into an Emacs minibuffer with M-:, it executes just fine.

How can I properly install a package from MELPA (or other repository) from the command line without an interactive session?

1
  • I understand what you're trying to do, and it might make sense to have a look at the guix package manager. I believe it would suits your needs. – aadcg Jun 2 '20 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.