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:
- CPU: 1.6 GHz or faster processor.
- RAM: 1 GB for 32-bit or 2 GB for 64-bit systems.
- Disk Space: 2 GB. (Additional space might be required for extensions, SDKs, and other development tools).
Recommended Requirements:
- CPU: Modern dual-core processor.
- RAM: 2 GB or more.
- 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:
- Using the Ubuntu Software Center.
- Downloading and installing the .deb package from the official VSCode website.
- Using the Command Line with the APT package tool (after adding the Microsoft repository and key).
- Installing via the Snapcraft store (using Snap).
- Runtime Executable VSCode without Installing
- 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.
Type “Ubuntu Software” in the search bar and click on the corresponding result to launch the Ubuntu Software Center.
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.
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.
If prompted, enter your password to authenticate the installation.
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 Code → Help → About
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).
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/
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:
Right-click on the downloaded compressed file, click Extract Here.
Right click on executable code file --> run or double click with mouse.
With this method, Visual Studio Code installation is completed.
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
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.
On Linux, this is usually /usr/bin/git
.
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
).
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.
Open the source control panel (Ctrl
+ Shift
+ G
).
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