How to install VS Code on Linux
How to Install VS Code on Linux: Complete Guide for All Distributions
Visual Studio Code (VS Code) has become one of the most popular code editors among developers worldwide, and for good reason. This free, open-source editor developed by Microsoft offers powerful features, extensive customization options, and excellent performance across all major operating systems, including Linux.
Whether you're a beginner just starting your coding journey or an experienced developer switching to Linux, this comprehensive guide will walk you through multiple methods to install VS Code on your Linux system. We'll cover installation procedures for various Linux distributions and provide troubleshooting tips to ensure a smooth setup process.
What is Visual Studio Code?
Visual Studio Code is a lightweight yet powerful source code editor that runs on Windows, macOS, and Linux. It comes with built-in support for JavaScript, TypeScript, and Node.js, while offering rich ecosystems of extensions for other languages and frameworks including C++, C#, Java, Python, PHP, Go, and .NET.
Key features that make VS Code popular among Linux users include:
- Intelligent code completion
- Built-in Git integration
- Integrated terminal
- Extensive debugging capabilities
- Customizable themes and extensions
- Cross-platform compatibility
- Regular updates and active community support
System Requirements
Before installing VS Code on your Linux system, ensure your machine meets the following minimum requirements:
Hardware Requirements
- RAM: 1 GB minimum (2 GB recommended)
- Storage: 200 MB of available disk space
- Processor: 1.6 GHz or faster processor
Supported Linux Distributions
VS Code officially supports the following Linux distributions:
- Ubuntu 18.04 and later
- Debian 9 and later
- Red Hat Enterprise Linux 8 and later
- Fedora 32 and later
- SUSE Linux Enterprise Server 12 and later
- openSUSE Leap 15.2 and later
- CentOS 8 and later
- Arch Linux
- Manjaro
Method 1: Installing VS Code Using Snap Package Manager
The Snap package manager provides the easiest way to install VS Code on most Linux distributions. Snap packages are universal packages that work across different Linux distributions and automatically handle dependencies.
Step 1: Install Snapd (if not already installed)
Most modern Linux distributions come with snapd pre-installed. If your system doesn't have it, install it using your distribution's package manager:
For Ubuntu/Debian:
```bash
sudo apt update
sudo apt install snapd
```
For Fedora:
```bash
sudo dnf install snapd
```
For Arch Linux:
```bash
sudo pacman -S snapd
sudo systemctl enable --now snapd.socket
```
Step 2: Install VS Code via Snap
Once snapd is installed, you can install VS Code with a single command:
```bash
sudo snap install --classic code
```
The `--classic` flag is necessary because VS Code requires access to system resources outside of the snap sandbox.
Step 3: Launch VS Code
After installation, you can launch VS Code by:
- Typing `code` in the terminal
- Searching for "Visual Studio Code" in your application menu
- Running `code ` to open a specific file
Advantages of Snap Installation
- Automatic updates
- Universal compatibility across distributions
- Sandboxed environment for security
- Simple installation process
Method 2: Installing VS Code Using APT (Debian/Ubuntu)
For Debian-based distributions like Ubuntu, you can install VS Code using the APT package manager by adding Microsoft's official repository.
Step 1: Update System Packages
```bash
sudo apt update
sudo apt upgrade
```
Step 2: Install Required Dependencies
```bash
sudo apt install wget gpg
```
Step 3: Add Microsoft's GPG Key
```bash
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
```
Step 4: Add Microsoft Repository
```bash
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
```
Step 5: Install VS Code
```bash
sudo apt update
sudo apt install code
```
Advantages of APT Installation
- Integration with system package manager
- Easy updates through regular system updates
- Better integration with desktop environment
Method 3: Installing VS Code Using RPM (Red Hat/Fedora/CentOS)
For Red Hat-based distributions, you can use the RPM package manager or DNF/YUM.
Step 1: Import Microsoft's GPG Key
```bash
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
```
Step 2: Add Microsoft Repository
Create a new repository file:
```bash
sudo tee /etc/yum.repos.d/vscode.repo << 'EOF'
[code]
name=Visual Studio Code
baseurl=https://packages.microsoft.com/yumrepos/vscode
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc
EOF
```
Step 3: Install VS Code
For Fedora (using DNF):
```bash
sudo dnf check-update
sudo dnf install code
```
For CentOS/RHEL (using YUM):
```bash
sudo yum check-update
sudo yum install code
```
Method 4: Installing VS Code Using Flatpak
Flatpak is another universal package manager that provides sandboxed applications across Linux distributions.
Step 1: Install Flatpak
For Ubuntu/Debian:
```bash
sudo apt install flatpak
```
For Fedora:
```bash
sudo dnf install flatpak
```
Step 2: Add Flathub Repository
```bash
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
```
Step 3: Install VS Code
```bash
flatpak install flathub com.visualstudio.code
```
Step 4: Launch VS Code
```bash
flatpak run com.visualstudio.code
```
Method 5: Installing VS Code Using AppImage
AppImage provides portable applications that run on most Linux distributions without installation.
Step 1: Download VS Code AppImage
Visit the [VS Code download page](https://code.visualstudio.com/Download) and download the AppImage file, or use wget:
```bash
wget https://code.visualstudio.com/sha/download?build=stable&os=linux-x64 -O code.AppImage
```
Step 2: Make the AppImage Executable
```bash
chmod +x code.AppImage
```
Step 3: Run VS Code
```bash
./code.AppImage
```
Optional: Integrate with System
To integrate the AppImage with your desktop environment:
```bash
./code.AppImage --appimage-extract
sudo mv squashfs-root /opt/vscode
sudo ln -s /opt/vscode/code /usr/local/bin/code
```
Method 6: Installing from DEB Package (Manual Installation)
You can also download and install the DEB package directly from Microsoft's website.
Step 1: Download the DEB Package
```bash
wget https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-x64 -O code.deb
```
Step 2: Install the Package
```bash
sudo dpkg -i code.deb
```
Step 3: Fix Dependencies (if needed)
```bash
sudo apt-get install -f
```
Post-Installation Configuration
After successfully installing VS Code, you can enhance your development experience with these configuration steps:
Setting Up VS Code as Default Editor
To set VS Code as your default text editor:
```bash
sudo update-alternatives --install /usr/bin/editor editor /usr/bin/code 100
```
Installing Essential Extensions
Launch VS Code and install these popular extensions:
1. Python - For Python development
2. GitLens - Enhanced Git capabilities
3. Bracket Pair Colorizer - Color-coded brackets
4. Live Server - Local development server
5. Prettier - Code formatter
Customizing Settings
Access VS Code settings through:
- File → Preferences → Settings
- Keyboard shortcut: `Ctrl+,`
Common customizations include:
- Font size and family
- Theme selection
- Auto-save configuration
- Tab size and indentation
Troubleshooting Common Issues
Issue 1: Command 'code' Not Found
Solution:
Add VS Code to your PATH by adding this line to your `~/.bashrc` or `~/.zshrc`:
```bash
export PATH="$PATH:/usr/share/code/bin"
```
Then reload your shell:
```bash
source ~/.bashrc
```
Issue 2: VS Code Won't Start
Possible Solutions:
1. Check system requirements - Ensure your system meets minimum requirements
2. Update graphics drivers - VS Code uses GPU acceleration
3. Disable GPU acceleration - Launch with `code --disable-gpu`
4. Clear VS Code cache:
```bash
rm -rf ~/.config/Code/User/workspaceStorage
rm -rf ~/.config/Code/CachedExtensions
```
Issue 3: Permission Errors
If you encounter permission errors when installing extensions:
```bash
sudo chown -R $(whoami) ~/.vscode
```
Issue 4: Snap Installation Issues
If the snap installation fails:
1. Enable snap support:
```bash
sudo systemctl enable --now snapd.socket
```
2. Update snap core:
```bash
sudo snap refresh core
```
Issue 5: Repository Key Errors
If you get GPG key errors:
```bash
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
```
Updating VS Code
Snap Updates
Snap packages update automatically, but you can force an update:
```bash
sudo snap refresh code
```
APT Updates
Update through the regular system update process:
```bash
sudo apt update && sudo apt upgrade
```
Manual Updates
For AppImage or manual installations, download the latest version and replace the existing files.
Uninstalling VS Code
If you need to remove VS Code from your system:
Snap Removal
```bash
sudo snap remove code
```
APT Removal
```bash
sudo apt remove code
sudo apt autoremove
```
Complete Removal (including user data)
```bash
rm -rf ~/.config/Code/
rm -rf ~/.vscode/
```
Alternative Code Editors for Linux
While VS Code is excellent, consider these alternatives:
- VSCodium - Open-source version of VS Code without Microsoft telemetry
- Atom - GitHub's hackable text editor (now deprecated)
- Sublime Text - Fast and lightweight editor
- Vim/Neovim - Terminal-based editors
- Emacs - Extensible text editor
- JetBrains IDEs - Specialized IDEs for different languages
Conclusion
Installing Visual Studio Code on Linux is straightforward with multiple methods available to suit different preferences and system configurations. The Snap installation method offers the easiest approach for most users, while the APT/RPM methods provide better system integration for package management.
Choose the installation method that best fits your Linux distribution and workflow preferences. The Snap method works universally across distributions, while distribution-specific package managers offer tighter system integration. For portable usage or testing, AppImage provides an excellent solution.
Remember to keep your VS Code installation updated to benefit from the latest features, security patches, and performance improvements. With proper installation and configuration, VS Code will serve as a powerful development environment for your Linux-based coding projects.
Whether you're developing web applications, working with Python scripts, or managing complex software projects, VS Code on Linux provides the tools and flexibility needed for modern software development. Take advantage of its extensive extension ecosystem and customization options to create a development environment tailored to your specific needs.