Steps to Install VSCode on Ubuntu 22.04 [6 Methods]


Ubuntu

Author: Omer Cakmak
Reviewer: Deepak Prasad

Installing Visual Studio Code on Ubuntu is a fundamental step for anyone looking to establish a powerful coding environment. Visual Studio Code, often abbreviated as VS Code, is a renowned code editor appreciated for its lightweight nature and extensibility. This guide is tailored to walk you through the process of how to 'install VS Code Ubuntu,' enabling you to unlock a world of programming possibilities.

Whether you're a seasoned developer or just embarking on your coding journey, having a versatile and user-friendly code editor is essential. With the step-by-step instructions provided here, you'll be equipped to seamlessly 'install VS Code Ubuntu,' harnessing its potential to enhance your coding efficiency and overall experience. Join us as we explore the installation process and set the stage for a productive coding venture on your Ubuntu system.

 

Minimum and Recommended Hardware Requirements

Minimum Requirements:

  1. CPU: 1.6 GHz or faster processor.
  2. RAM: 1 GB for 32-bit or 2 GB for 64-bit systems.
  3. Disk Space: 2 GB. (Additional space might be required for extensions, SDKs, and other development tools).

Recommended Requirements:

  1. CPU: Modern dual-core processor.
  2. RAM: 2 GB or more.
  3. Disk Space: SSD and 4 GB or more. (For smoother performance, especially when dealing with larger codebases).

 

Different methods to Install VSCode on Ubuntu 22.04

Here's a list of possible methods to install Visual Studio Code (VSCode) in Ubuntu 22.04:

  1. Using the Ubuntu Software Center.
  2. Downloading and installing the .deb package from the official VSCode website.
  3. Using the Command Line with the APT package tool (after adding the Microsoft repository and key).
  4. Installing via the Snapcraft store (using Snap).
  5. Runtime Executable VSCode without Installing
  6. Using a third-party package manager like Flatpak.

 

1. Installing Visual Studio Code via Ubuntu Software Center

Visual Studio Code can be installed with Ubuntu Software Center without using a terminal. Actually, this way of installation is installation from SNAP Store. Ubuntu Software Center pulls the package from the snap store and installs it on the system.

Click on the Ubuntu logo or "Show Applications" at the bottom-left corner of the screen.

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]


Type “Ubuntu Software” in the search bar and click on the corresponding result to launch the Ubuntu Software Center.

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]

 


In the Ubuntu Software Center, there's a search icon (usually a magnifying glass) at the top. Click on it. Enter "Visual Studio Code" in the search bar and press Enter.

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]

 


You should see "Visual Studio Code" appear in the search results. Click on it to view more details.

You will now be on the detailed page for Visual Studio Code. Here, you'll see an “Install” button. Click the “Install” button.

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]


If prompted, enter your password to authenticate the installation.

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]


The installation process will begin. You can monitor the progress with the progress bar. Wait until the installation completes.

Once installed, you can close the Ubuntu Software Center.

To launch VS Code, click on the Ubuntu logo or "Show Applications" at the bottom-left corner of the screen again. Type "Visual Studio Code" in the search bar and click on the VS Code icon to launch it.

This is a screenshot from Visual Studio CodeHelp About

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]

 

 

2. Using the .deb Package to Install Visual Studio Code

Navigate to the official VS Code website: https://code.visualstudio.com/. You'll be presented with several download options. Click on the ".deb" option (it's usually labeled for Debian/Ubuntu).

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]

 

The download will start, and once complete, you should have a file named something like code_x.xx.x-xxxxxx_amd64.deb in your Downloads directory (the name may vary based on the version).

$ ls -l Downloads/
total 94076
-rw-rw-r-- 1 deepak deepak 96329592 Aug 22 10:51 code_1.81.1-1691620686_amd64.deb

Open a terminal and Navigate to the directory where the .deb file was downloaded. By default, it should be the Downloads directory:

cd ~/Downloads

Now, use the dpkg command to install the package:

sudo dpkg -i code_1.81.1-1691620686_amd64.deb 

Sample Output

Selecting previously unselected package code.
(Reading database ... 268728 files and directories currently installed.)
Preparing to unpack code_1.81.1-1691620686_amd64.deb ...
Unpacking code (1.81.1-1691620686) ...
Setting up code (1.81.1-1691620686) ...
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) ...

If there are any missing dependencies, you can fix and complete the installation using:

sudo apt-get install -f

Verify the version:

$ code --version
1.81.1
6c3e3dba23e8fadc360aed75ce363ba185c49794
x64

Once the installation is complete, you can launch VS Code by either typing code in the terminal or by searching for "Visual Studio Code" in your application menu and clicking on its icon.

 

3. Installing Visual Studio Code via Command Line (APT):

Installing Visual Studio Code (VS Code) using the APT package manager involves adding Microsoft's official repository and the corresponding key to ensure the authenticity of the software. Here's a step-by-step guide to do that:

 

Adding Microsoft's GPG Key:

Before you can install software from a repository, it's a good idea to add its GPG key. This ensures that the software you're installing is authentic and hasn't been tampered with.

curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

Adding the VS Code Repository:

Add the Visual Studio Code repository to your system so that you can install it using apt.

sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"

Updating the Package Lists:

Before installing new software from a newly added repository, update your system's package lists.

sudo apt update

Installing Visual Studio Code:

Now that the repository is added, you can install VS Code using apt-get (or simply apt in newer versions of Ubuntu).

sudo apt install code

Launching Visual Studio Code: Once the installation is complete, you can start VS Code in either of two ways:

  • Type code in the terminal.
  • Search for "Visual Studio Code" in your application menu and click on its icon.

 

 

4. Installing Visual Studio Code via Snap

Snap is a package management system that allows you to install software in a containerized format, ensuring it won't interfere with other system software. Visual Studio Code is available as a snap package, and installing it using Snap is straightforward.

 

Ensure Snapd is Installed:

Ubuntu 18.04 LTS and later come with snapd pre-installed. If you're using an older version of Ubuntu or have removed snapd, you'll need to install it:

sudo apt update
sudo apt install snapd

Install Visual Studio Code:

Once snapd is ready, you can install Visual Studio Code using the following command:

sudo snap install code --classic

The --classic flag is used because the VS Code snap requires full access to the system, similar to a traditionally packaged application. This is to ensure VS Code can access your files, tools, and other required components.

Launching Visual Studio Code:

After installation, you can launch Visual Studio Code in any of the following ways:

  • By typing code in the terminal.
  • By searching for "Visual Studio Code" in your application menu and clicking on its icon.

If you get below error:

$ code -v
-bash: /usr/bin/code: No such file or directory

then you might need to log out and log back in or even restart your computer. This ensures that all the necessary paths are sourced correctly.

Or alternatively you can reference the snap binary using:

snap run code

OR

/snap/bin/code

In most systems, the Snap binary directory (/snap/bin/) should be added to your PATH automatically, allowing you to run Snap-installed apps just by their name. If it works in a new session, you can also update the PATH in your current session with:

export PATH=$PATH:/snap/bin/

 

NOTE:
Snap packages are auto-updated in the background, so your VS Code installation will always be up-to-date. Snap applications are stored in a sandboxed environment, which can increase security but might also introduce slight performance overhead in some cases.

If you wish to uninstall Visual Studio Code installed via Snap, you can use the following command:

sudo snap remove code

 

5: Using Runtime executable VSCode without installing

This method is always applied when there is no access to the package repositories. You can use the tar.gz file from anywhere by taking it to a portable memory.

Now download the file by going to the Visual Studio Code official download address:

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]


Right-click on the downloaded compressed file, click Extract Here.

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]


Right click on executable code file --> run or double click with mouse.

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]


With this method, Visual Studio Code installation is completed.

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]

 

6. Alternative Methods (Using Flatpak)

Flatpak is another containerized package management system similar to Snap, but with a focus on desktop applications specifically. It uses a central repository called Flathub where users can find and install applications.

First, ensure you have Flatpak installed:

sudo apt install flatpak

Add the Flathub repository:

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

Install Visual Studio Code from Flathub:

flatpak install flathub com.visualstudio.code

Sample Output:

Looking for matches…
Required runtime for com.visualstudio.code/x86_64/stable (runtime/org.freedesktop.Sdk/x86_64/22.08) found in remote flathub
Do you want to install it? [Y/n]: Y

com.visualstudio.code permissions:
    ipc                   network               pulseaudio                   ssh-auth       x11       devices       devel
    file access [1]       dbus access [2]       system dbus access [3]       tags [4]

    [1] host, xdg-config/gtk-3.0, xdg-config/kdeglobals:ro
    [2] com.canonical.AppMenu.Registrar, com.canonical.AppMenu.Registrar.*, org.freedesktop.Flatpak, org.freedesktop.Notifications, org.freedesktop.secrets
    [3] org.freedesktop.login1
    [4] proprietary


        ID                                             Branch                 Op            Remote             Download
 1. [✓] org.freedesktop.Platform.GL.default            22.08                  i             flathub            143.1 MB / 143.1 MB
 2. [✓] org.freedesktop.Platform.GL.default            22.08-extra            i             flathub             16.2 MB / 143.1 MB
 3. [✓] org.freedesktop.Platform.openh264              2.2.0                  i             flathub              1.2 MB / 944.3 kB
 4. [✓] org.freedesktop.Sdk.Locale                     22.08                  i             flathub             18.0 kB / 339.3 MB
 5. [✓] org.freedesktop.Sdk                            22.08                  i             flathub            450.0 MB / 515.9 MB
 6. [/] com.visualstudio.code                          stable                 i             flathub             22.2 MB / 100.2 MB

Installing 6/6… █████▌                28%  5.6 MB/s  00:10

To launch, you can use:

flatpak run com.visualstudio.code

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]

 

Uninstall Visual Studio Code from Flatpak

First, check if VSC is indeed installed via Flatpak:

flatpak list

If you see Visual Studio Code in the list, proceed with its removal:

flatpak uninstall com.visualstudio.code

After removing VSC, you can then uninstall Flatpak itself:

sudo apt remove flatpak

If you want to remove the repositories and applications' data associated with Flatpak, you can delete the Flatpak directory from your home:

rm -rf ~/.var/app
rm -rf ~/.local/share/flatpak

And, if you added a global installation for all users, also consider:

sudo rm -rf /var/lib/flatpak/

It's always good to update the package list after removing software:

sudo apt update

 

Integrating Git with Visual Studio Code

1. Installing and Setting up Git:

Install Git: If you're on a Debian/Ubuntu-based distribution, you can use the following:

sudo apt update
sudo apt install git

Initial Git Configuration: Once installed, configure Git with your personal info:

git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"

NOTE: You can also choose to define these config at local scope for a certain repository. In such case navigate to your repository cd /path/to/your/repo and execute the same set of command without --global flag.

 

2. Configuring VS Code to Work with Git

VSCode has built-in Git support, so typically no additional configuration is required. However, if you've installed Git after VSCode, you might need to restart VSCode.

Ensure Git Path: Ensure that the path to the Git executable is correctly set in VSCode. Go to File > Preferences > Settings (or Ctrl + ,). Search for "Git: Path" and make sure it points to the Git executable.

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]

 

On Linux, this is usually /usr/bin/git.

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]

 

Install Git Extension (if desired): While VSCode has built-in Git support, the GitLens extension offers enhanced capabilities. To install it, visit the link or search for "GitLens" in the VSCode Extensions view (Ctrl + Shift + X).

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]

 

3. Basic Git Operations within VS Code

You can check our Detailed GIT Tutorial

 

Initialize a Repository:

To initialize a repository, open your project directory in VSCode.

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]

 

Open the source control panel (Ctrl + Shift + G).

Steps to Install VSCode on Ubuntu 22.04 [6 Methods]

Click on "Initialize Repository". This will create a .git directory in your project folder.

root@deepak-VirtualBox:/workspacee# ls -al
total 12
drwxrwxrwx  3 root   root   4096 Aug 22 12:28 .
drwxr-xr-x 22 root   root   4096 Aug 22 12:16 ..
drwxrwxr-x  7 deepak deepak 4096 Aug 22 12:28 .git

 

Commit Changes:

  • Make changes to your files.
  • In the source control panel, you'll see a list of changes. Stage changes by clicking the '+' icon next to each file or stage all with the '+' icon at the top.
  • Add a commit message in the text box at the top, then press the checkmark or Ctrl + Enter to commit.

 

Branching and Merging:

  • To create a new branch, click on the current branch name (usually "master" or "main") at the bottom-left of the window. Type the new branch's name and press Enter.
  • To merge branches, open the command palette (Ctrl + Shift + P), search for "Git: Merge Branch", and select the branch you want to merge into the current one.

 

Syncing with Remote Repositories:

  • If you have a remote repository (e.g., on GitHub), you can push and pull changes from within VSCode.
  • Use the "..." menu in the source control panel to access push, pull, and other operations.

 

Uninstall Visual Studio Code Completely

In general you can uninstall visual studio code using apt package manager.

sudo apt remove code

If you have installed VSCode using snap then you should use:

sudo snap remove code

If installed using Flatpak

flatpak uninstall com.visualstudio.code

Post-Uninstallation Cleanup:

Regardless of the method, Remove the user-specific configurations and extensions located in ~/.config/Code/ by deleting this directory:

rm -rf ~/.config/Code/

Update your system's package cache (primarily for APT installations):

sudo apt update

 

Summary

We delved into the installation and uninstallation of Visual Studio Code (VSCode) on Ubuntu, detailing several methods: using APT from the command line, the Ubuntu Software Center, direct .deb package downloads, Snap, and alternative methods. In addition, we discussed how to integrate Git with VSCode, explaining both global and local Git configurations. The importance of understanding the context of a repository for configuration, evidenced by the "fatal: not in a git directory" error, was underscored. Through this comprehensive overview, the versatility of VSCode's setup and its seamless Git integration were highlighted.

 

References

code.visualstudio.com - Visual Studio Code on Linux

 

Views: 1,286
Omer Cakmak

Omer Cakmak

He is highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment