DEV Community

Cover image for Bulk install VS Code extensions
Ramo Mujagic
Ramo Mujagic

Posted on • Originally published at ramomujagic.com

Bulk install VS Code extensions

If you are reading this, you probably already know what VS Code and VS Code extensions are. Usual way to install extensions is through VS Code Interface. It is really easy and intuitive. However, every extension needs to be installed one by one.

This is great if you need to install one extension at the time, which is usually the case, but what if you need to install 20 or more extensions? It can become a time consuming process.

You might wonder, why would I ever need to install 20 or more extensions at the time? Let's answer this question in the next section.

The reason why

Recently, I needed to setup a new working environment and basically replicate everything that I already have on the old machine on the new one.

For some, this can be fun and interesting. It also gives you an opportunity to add some changes to your setup that you didn't want to do before. But when you do it often or when you are happy with your current setup, it can be really tedious to do it again from scratch.

Anyways, eventually, I needed to setup VS Code to be exactly the same as on the old machine. However, I have noticed that I could not install extensions all at once. Since I have more than 20 extensions that I needed to install, I did not want to do it manually, one by one.

Bulk install script

I decided to make a script that can automate the extensions installation process. For me, it would be good enough to loop over a list of extensions and install them.

I spent some time trying out the code command and possible options. Luckily, it is possible to use the code --list-extensions command to list all installed extensions and also code --install-extension <extension_id> to install the extension.

Lastly, I decided to make it a bit more robust and added some logging so it's easy to see what the script is doing. Source code is available here.

How to use it

First, you need to prepare a .txt file that will be used as an input for the script. This file should contain a list of all VS Code extensions, one per line. Here is a sample of how file content should look like.

...
akamud.vscode-theme-onedark
akamud.vscode-theme-onelight
dbaeumer.vscode-eslint
eamodio.gitlens
esbenp.prettier-vscode
formulahendry.auto-rename-tag
mikestead.dotenv
...
Enter fullscreen mode Exit fullscreen mode

Every extension must be in <publisher>.<name> format. Make sure that the file is correctly formatted and that there are no extra spaces or blank lines in the file.

Alternatively, you can use a code command to extract the list of extensions from your current VS Code installation.

code --list-extensions > extensions-list.txt
Enter fullscreen mode Exit fullscreen mode

When the command is executed, it will generate a list of all installed extensions and save them into the extensions-list.txt file. You can change the file name in the command if you want.

Running the script

Next step would be to run the script and use the previously created file as an input. It can all be done in just one command like this.

curl -fsSL https://raw.githubusercontent.com/rmmgc/vscode-extensions-bulk-install/main/bulk-install.sh | sh -s <path_to_input_file>
Enter fullscreen mode Exit fullscreen mode

For the script to work properly, VS Code needs to be installed and the code command must be exported on the PATH.

When the command is executed, it will get text content of the script from the URL and pipe the output to the sh command. The script file itself will not be saved on your machine. Additionally, the path to the input file is passed as an argument to the script.

Make sure to replace path_to_input_file with a path to the input file that has a list of extensions.

After execution, you should see a detailed log in the terminal. It might look something like this.

...

🔧 Working on dbaeumer.vscode-eslint extension.
✅ Extension already installed.
Skipping further steps.

🔧 Working on formulahendry.auto-rename-tag extension.
Running: code --install-extension formulahendry.auto-rename-tag.
Installing extensions...
Installing extension 'formulahendry.auto-rename-tag'...
(node:93018) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `Electron --trace-deprecation ...` to show where the warning was created)
Extension 'formulahendry.auto-rename-tag' v0.1.10 was successfully installed.
✅ Extension installed successfully.

🔧 Working on mikestead.dotenv extension.
✅ Extension already installed.
Skipping further steps.

💡 Check the logs above for detailed report.
🎉 Successfully finished.
Enter fullscreen mode Exit fullscreen mode

All missing extensions should be installed. In case some extensions were already installed before running the script, they will be skipped.

Conclusion

It became boring always installing VS Code extensions whenever setting up a new working environment. That's why I decided to create and share a script that can help to speed up this process a little bit.


Check out other articles on my blog.

Top comments (0)