How to install multiple extensions in VSCode using command line

Viewed 4834

How can I install multiple extensions in VSCode using the cli? I tried:

code --install-extension xyz.local-history jock.svg

but it only installs the first extension xyz.local-history.

Installing extensions...
Installing extension 'xyz.local-history' v1.7.0...
(node:10874) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
Extension 'xyz.local-history' v1.7.0 was successfully installed.
5 Answers

If you are use Unix/Linux create a bash script with a loop. In this case I want to backup the extensions list and install again:

First create a list of the extensions:

$ code --list-extensions > extensions.txt

Create a bash script for example with the name vscode-extension-install.sh and input the following code:

#!/usr/bin/env bash

cat extensions.txt | while read extension || [[ -n $extension ]];
do
  code --install-extension $extension --force
done

Then run:

$ ./vscode-extension-install.sh

Example output:

Installing extensions...
Installing extension 'visualstudioexptteam.vscodeintellicode' v1.2.6...
Extension 'visualstudioexptteam.vscodeintellicode' v1.2.6 was successfully installed.
Installing extensions...
Installing extension 'vscode-icons-team.vscode-icons' v10.0.0...
Extension 'vscode-icons-team.vscode-icons' v10.0.0 was successfully installed.
...

From my gists

Declare a variable, containing the name of all extensions you want to install... after you have it, you can iterate doing the installation one by one...

for extensions in ms-python.python ms-azure-devops.azure-pipelines ms-mssql.mssql 
do code --install-extension $extensions
done

Maybe you also have to add your code.cmd path, but if your command is working typring code, this will be enough to do the taks Happy coding!

If you are on Windows and do not use WSL, try a PowerShell loop.

  1. Put all desired extensions in a text file (as in Linux example above) - say extensions.txt
  2. Iterate over them with: Get-Content extensions.txt | ForEach-Object {code --install-extension $_}

Note: this would work on every system supporting PowerShell

It's possible to pass the --install-extension argument multiple times and so install several extensions with just one line.

code --install-extension dbaeumer.vscode-eslint --install-extension esbenp.prettier-vscode

The documentation for this can be found in Extension Marketplace. Running this both extensions are installed but Installing extensions... is only found once in the output.

Disclaimer: This is not a command line approach, but rather a graphical way to install existing extensions on a new system using .vsix package, and might help some others with the same.


This method to install extensions on a new system (with reference to an existing system) requires Yeoman VS Code extension generator and vsce (or nodejs to install these).

  1. On the existing machine, generate an extension pack (more details here)
npm install -g yo generator-code

yo code

First command installs Yeoman VS Code generator, second creates the extension pack (choose default options as below. The created package.json contains all extensions in the pack, you can modify that list)

enter image description here

enter image description here

enter image description here

  1. On the existing machine, package the extension pack created above into a .vsix file
npm install -g vsce
 
vsce package

First command installs vsce, second packages the extension into a .vsix file (run from the root of the extension pack created above)

enter image description here

  1. On the new system, install the .vsix file
code --install-extension extension-pack-0.0.1.vsix
  1. Open VS Code on the new system, access this extension, install all required extensions via GUI

enter image description here

Related