How to Install Visual Studio Code on Fedora 40 or 39

Visual Studio Code (VSCode) is a highly popular code editor developed by Microsoft, offering a rich set of features that include debugging, syntax highlighting, intelligent code completion, and integrated Git control. It’s widely favored by developers for its versatility, extensive extension library, and support for a vast array of programming languages and frameworks. VSCode comes in two primary versions: the stable build, which is recommended for most users, and the Insiders build, which provides early access to the latest features and updates.

For Fedora 40 or 39, VSCode can be installed using the Microsoft RPM repository, which provides both the latest stable and Insiders builds. This method ensures you have the most up-to-date version directly from Microsoft, with automatic updates for future releases. Alternatively, VSCode can be installed via Flatpak from Flathub, though this method only offers the standard stable build. Flatpak provides a sandboxed environment that might appeal to users who prefer isolated application management. This guide will walk you through both installation methods, helping you choose the best option for your development environment.

Method 1: Install Visual Studio Code via RPM

Update Fedora Before Visual Studio Code Installation

Before diving into the installation process, ensuring your Fedora system is up-to-date is crucial. This practice helps avoid potential issues during the installation and keeps your system running smoothly.

To update your Fedora system, open a terminal and execute the following command:

sudo dnf upgrade --refresh

Import Visual Studio Code RPM

Visual Studio Code isn’t available by default in the standard Fedora repositories. However, you can easily set up and import the official Visual Studio Code repository on your system by following these steps:

Import VSCode GPG key:

To verify the authenticity of the installed packages, start by importing the GPG key with this command:

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc

Import VSCode RPM Repository:

Next, import the repository using the command below. This command creates a new repository file with the necessary configuration to access the Visual Studio Code packages:

printf "[vscode]\nname=packages.microsoft.com\nbaseurl=https://packages.microsoft.com/yumrepos/vscode/\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc\nmetadata_expire=1h" | sudo tee -a /etc/yum.repos.d/vscode.repo

Upon successful execution, you should see the following output in your terminal:

[vscode]
name=Visual Studio Code
baseurl=https://packages.microsoft.com/yumrepos/vscode
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc

With the repository in place, you can now install Visual Studio Code on Fedora Linux.

Finalize Visual Studio Code Installation

There are two options available: the stable build and the insider build. For most users, we recommend installing the stable build.

Note: You can install both versions of Visual Studio Code stable and insiders build. if you like, they share separate installations.

Option 1: Install VSCode stable build (Recommended)

sudo dnf install code

Option 2: Install VSCode insiders build (upstream)

If you prefer to have access to the latest features and updates with the Visual Studio Insiders edition, you can install the insider build by running the following:

sudo dnf install code-insiders

Note: The first time you install Visual Studio Code, you should see the GPG key being imported, as shown in the example below:

Importing GPG key 0xBE1229CF:
 Userid     : "Microsoft (Release signing) <gpgsecurity@microsoft.com>"
 Fingerprint: BC52 8686 B50D 79E3 39D3 721C EB3E 94AD BE12 29CF
 From       : https://packages.microsoft.com/keys/microsoft.asc

Install Visual Studio Code via Flatpak and Flathub

This secondary section provides instructions on installing Visual Studio Code on Fedora Linux utilizing Flatpak and the Flathub repository, showcasing an alternative to the conventional DNF method.

Enable Flathub for Visual Studio Code

First, ensure your system includes the Flathub repository, which houses various applications, including Visual Studio Code. If not already added, use the command below to add the Flathub repository to Flatpak:

flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

Install Visual Studio Code via Flatpak Command

With Flatpak and Flathub now operational, advance to the installation of Visual Studio Code by dispatching the following command:

flatpak install flathub com.visualstudio.code

This command commences a search for the Visual Studio Code package within the Flathub repository and triggers its installation on your system.

Troubleshooting Flathub Activation on Fedora Linux

It might not activate as expected in some scenarios despite having imported Flathub on Fedora Linux.

To rectify this, enter the following command to enable Flathub:

flatpak remote-modify --enable flathub

Launch Visual Studio Code User Interface

Congratulations on successfully installing Visual Studio Code! Now, it’s time to launch the application and explore its features. Depending on your preferences, there are several ways to open Visual Studio Code.

CLI Methods to Launch VSCode

For those who prefer using the command line terminal, you can quickly launch Visual Studio Code with the following commands:

To launch the stable build, run the following command:

code

Alternatively, if you installed the insiders build, run the following command:

code-insiders

Alternatively, Flatpak installations need to run the alternative flatpak run command for VSCode:

flatpak run com.visualstudio.code

GUI Method to Launch VSCode

If you’re a desktop user who prefers not to use the command line terminal, you can easily open Visual Studio Code through the GUI. Here’s how:

  1. Click on the Activities button located in the top-left corner of your screen.
  2. Select Show Applications (represented by a grid icon) to display a list of installed applications.
  3. Find and click on the Visual Studio Code icon to launch the application.

Additional Visual Studio Code Commands

Update Visual Studio Code

It’s essential to keep Visual Studio Code up-to-date for the best performance and security. To check for updates across all DNF packages, including Visual Studio Code, use the following command:

sudo dnf update --refresh

Alternatively, for the Flatpak equivalent command to blanket check all Flatpak installations for updates, run the following command:

flatpak update

Remove Visual Studio Code

DNF Remove Method For Visual Studio Code

Suppose you no longer need Visual Studio Code or wish to switch to a different version. In that case, you can uninstall it using the appropriate command based on your installation:

sudo dnf remove code
sudo dnf remove code-insiders

If you’re sure you won’t reinstall Visual Studio Code in the future, you can also remove the repository from your system. To do this, execute the following command:

sudo rm /etc/yum.repos.d/vscode.repo

Flatpak Remove Method For Visual Studio Code

Alternatively, if you installed VSCode utilizing Flatpak, use the following command to remove it:

flatpak uninstall com.visualstudio.code

Closing Thoughts

By installing Visual Studio Code on your Fedora system via the Microsoft RPM repository, you can choose between the stable build or the Insiders build, ensuring that your development environment is always equipped with the latest tools and features. The Flatpak method, while limited to the stable build, offers a secure and isolated installation environment. Regular updates through these methods will keep your VSCode installation current, allowing you to take full advantage of its powerful features for coding on Fedora.

Leave a Comment