Microsoft Visual Studio Code is an open source, lightweight and powerful source code editor. It comes with built-in support for JavaScript, TypeScript and Node.js and has a rich ecosystem of extensions for other languages (such as C++, C#, Python, PHP, Go) and runtimes (such as .NET and Unity). It is a cross-platform code editor, so you can use it in Microsoft Windows, GNU/Linux, and Mac OS X. In this tutorial, we are going to see how to install Microsoft Visual Studio Code in Linux.
Table of Contents
Install Microsoft Visual Studio Code In Linux
Microsoft Visual Studio Code can be installed in the following ways:
- Using the installer file,
- From Snap store,
- Using repository.
Install Visual Studio Code using Installer File
The easiest way to install Visual Studio Code editor is to download the respective installer package and install it using your distribution's package manager. This will add the VS Code repository automatically, so you can update VS Code using the default package manager at any time.
Microsoft Visual Studio Code editor is available in .deb and .rpm package format. Go to the Visual Studio Coded official download page and download the suitable installer file for your Linux distribution.
After downloading the installer file, install it depends on your distribution type.
On Debian-based systems, run:
$ sudo dpkg -i Downloads/code_1.74.2-1671533413_amd64.deb
Sample Output:
Selecting previously un-selected package code. (Reading database ... 258240 files and directories currently installed.) Preparing to unpack .../code_1.74.2-1671533413_amd64.deb ... Unpacking code (1.74.2-1671533413) ... Setting up code (1.74.2-1671533413) ... Processing triggers for mailcap (3.70+nmu1ubuntu1) ... Processing triggers for gnome-menus (3.36.0-1ubuntu3) ... Processing triggers for desktop-file-utils (0.26-1ubuntu3) ... Processing triggers for shared-mime-info (2.1-2) ...
Next, run the following command to install missing dependencies:
$ sudo apt-get install -f
If you're on RPM-based systems, for example Fedora, the command to install Code is given below:
$ sudo dnf localinstall code-1.74.2-1671533504.el7.x86_64.rpm
Install Visual Studio Code from Snap Store
Visual Studio Code is available in Snap Store as well.
If snap support is enabled on your Linux system, you can install Visual Studio Code using the following command:
$ sudo snap install code --classic
Install Visual Studio Code from Repository
Microsoft developers has also made VS Code repositories for a few Linux distributions to make the installation process even easier.
For Arch Linux and its variants like EndeavourOS and Manjaro Linux, a community-maintained AUR for VS Code. To install VS Code from AUR, you can either use Paru or Yay helpers.
$ paru -S visual-studio-code-bin
Or,
$ yay -S visual-studio-code-bin
On Debian, Ubuntu and its derivatives, run these commands to to import VS Code signing key and add VS Code repository:
$ sudo apt-get install wget gpg $ wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg $ sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg $ sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list' $ rm -f packages.microsoft.gpg
Then, update the repository lists and install VS Code as shown below.
$ sudo apt install apt-transport-https $ sudo apt-get update $ sudo apt-get install code
On RHEL, CentOS, Fedora, run the following commands to import signing key and add VS Code repository:
$ sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc $ sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
Update the package cache and install VS Code as shown below.
$ dnf check-update $ sudo dnf install code
On older versions, use yum instead of dnf:
$ yum check-update $ sudo yum install code
On SUSE/openSUSE, run the following commands to import signing key and VS Code repository.
$ sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc $ sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ntype=rpm-md\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/zypp/repos.d/vscode.repo'
Update the package cache and install VS Code as shown below.
$ sudo zypper refresh $ sudo zypper install code
On Nix OS:
$ nix-env -i vscode
Run Visual Studio Code
Once installed, you can open the VS Code editor using command:
$ code
Choose a theme for your Code editor and click "Mark done" at the bottom.
You can now start writing your code by opening new file or choose the existing code from a file or git clone your repository directly from the Code editor.
I am going to choose a new text file. You can alternatively choose a Jupyter notebook too.
You can now start writing your code. You can also select a programming language of your choice from the list or open a different editor to get started.
If you don't want to see the above message every time, you can simply click the "don't show again" link.
Congratulations! You have successfully installed Microsoft Visual Studio Code in your Linux distribution.
Set VS Code as Default Editor
You can make VS Code as default text editor for text files with the following command:
# xdg-mime default code.desktop text/plain
You can also use the "Debian alternatives system" to set VS Code as the default editor, without concern for the MIME type.
To set VS Code as default editor, run:
$ sudo update-alternatives --set editor /usr/bin/code
If Visual Studio Code doesn't show up as an alternative to editor, you need to register it using command:
$ sudo update-alternatives --install /usr/bin/editor editor $(which code) 10
What next?
I have installed MS Visual Studio Code, now what? Refer the following links to getting started with Visual Code.
And, that's all for now. Have you tried Visual studio in Linux? What is your thoughts about it? Give us your feedback in the comment section below.
Resource: