How to Install and Use Visual Studio Code on Ubuntu for Programming

Introduction


Ubuntu is one of the most popular Linux distributions for software development because it offers a flexible environment, powerful command-line tools, and access to thousands of open-source applications. Whether you are learning Python, building websites, developing applications, or working with cloud technologies, Ubuntu provides a solid foundation for programming. However, writing and managing code becomes much easier when you have a reliable code editor.


Visual Studio Code, commonly known as VS Code, is a widely used source-code editor developed by Microsoft. It supports numerous programming languages, including Python, JavaScript, TypeScript, C, C++, Java, PHP, and HTML. Its features include syntax highlighting, code completion, debugging tools, integrated terminal access, Git integration, and a large extension marketplace.


Installing Visual Studio Code on Ubuntu allows you to combine the flexibility of Linux with a modern development environment. Instead of switching between multiple applications, you can write code, run terminal commands, inspect project files, manage source control, and troubleshoot errors from one interface.


Another advantage of VS Code is its flexibility. Beginners can start with a simple text file and gradually add extensions as their programming skills develop. Experienced developers can customize the editor for complex projects, remote development environments, containerized applications, and collaborative workflows.


This guide explains how to install Visual Studio Code on Ubuntu, configure the editor, create your first programming project, install useful extensions, use the integrated terminal, work with Git, debug programs, and troubleshoot common problems.


By following these steps, you will learn how to turn an Ubuntu computer into a practical programming workstation without requiring expensive development software.


1. What Is Visual Studio Code?


Visual Studio Code is a source-code editor designed to help developers write, understand, test, and maintain software.


Although its name resembles Microsoft Visual Studio, the two products are different. Visual Studio Code is a lightweight, extensible editor, while Visual Studio is a separate integrated development environment with a different feature set and supported workloads.


VS Code works on Linux, Windows, and macOS. Its core editing features support many programming languages, while extensions provide additional functionality for specific tools and development environments.


Some of the main features include:


Syntax highlighting: Makes programming code easier to read by applying colors to keywords, strings, functions, and other elements.

IntelliSense: Provides context-aware suggestions and information while writing supported code.

Integrated terminal: Lets you execute Linux commands without leaving the editor.

Debugging support: Allows you to inspect variables, set breakpoints, and investigate program behavior when the relevant debugger is configured.

Git integration: Helps you inspect changes, stage files, create commits, and work with source control.

Extensions: Adds support for languages, frameworks, formatters, themes, and other development tools.

Project navigation: Provides a file explorer for managing source files and folders.

Customizable interface: Lets you change themes, keyboard shortcuts, settings, and editor layouts.


These features make VS Code useful for both small learning projects and larger software development tasks.


For example, a beginner learning Python can use the editor to write a program, execute it in the terminal, and investigate errors. A web developer can create HTML, CSS, and JavaScript files in one project. A systems programmer can edit C or C++ source files and use external compilers from the integrated terminal.


The editor itself does not automatically install every compiler, interpreter, database, or runtime required by a project. You must install and configure those tools separately when necessary.


Understanding this distinction will help you configure VS Code correctly for your preferred programming language.


2. Check Your Ubuntu Version Before Installation


Before installing developer tools, it is helpful to identify the Ubuntu version you are using.


Open the terminal by pressing Ctrl + Alt + T.


Run:


lsb_release -a



This command displays information about your Linux distribution, including its release number when the utility is available.


You can also inspect:


cat /etc/os-release



The output includes information such as the distribution name and version.


Next, check whether your system architecture is compatible with the package you intend to install:


dpkg --print-architecture



Common results include amd64 for 64-bit x86 systems and arm64 for 64-bit ARM systems.


The architecture matters because software packages are built for specific processor types.


It is also sensible to refresh your package index before installing software through Ubuntu's package manager:


sudo apt update



This command updates the local package information using the repositories already configured on your system.


If your system has pending updates, you may choose to install them separately:


sudo apt upgrade



Review the proposed changes before confirming. You do not need to perform a full system upgrade every time you install an application, but keeping Ubuntu reasonably up to date can help with security and compatibility.


Once you know your Ubuntu version and architecture, you can choose an appropriate VS Code installation method.


3. Download Visual Studio Code from the Official Website


The simplest approach for many beginners is to download the official Debian package for Ubuntu.


Open your web browser and visit the official Visual Studio Code website:


https://code.visualstudio.com/


Choose the Linux download option and select the Debian package, commonly identified by its .deb file extension, when it is available for your architecture.


Save the downloaded package to your Downloads directory.


The exact filename may vary by release and processor architecture. Do not assume that the filename in an old tutorial will match the package you download today.


Once the download is complete, open the terminal and move to the Downloads directory:


cd ~/Downloads



List the available Debian packages:


ls -lh *.deb



If multiple packages are present, identify the file corresponding to the VS Code download.


You can install the package with APT by specifying its exact filename:


sudo apt install ./PACKAGE_NAME.deb



Replace PACKAGE_NAME.deb with the actual downloaded filename.


The ./ prefix tells APT to install a local package rather than search for a package by name in the configured repositories.


APT can also resolve many required dependencies from configured repositories.


If the package is incompatible with your architecture or Ubuntu environment, read the error message rather than forcing the installation.


After installation finishes, you can open Visual Studio Code from the application menu or continue with the terminal-based launch instructions below.


Downloading software from the official website helps reduce the risk of installing a modified or unrelated package. Always verify that you are using the genuine project website before downloading developer tools.


4. Install Visual Studio Code Using the Terminal


Developers who prefer the command line can install VS Code using Microsoft's official APT repository.


This approach is useful when you want the package manager to manage updates alongside other software.


The following procedure installs the Microsoft repository signing key and configures the repository. These commands assume a standard Ubuntu environment with the required utilities available.


First, install the utilities needed to retrieve and configure the repository:


sudo apt update

sudo apt install wget gpg



Create a directory for APT keyrings:


sudo install -d -m 0755 /etc/apt/keyrings



Download Microsoft's Linux package-signing key and convert it into a keyring file:


wget -qO- https://packages.microsoft.com/keys/microsoft.asc \

  | gpg --dearmor \

  | sudo tee /etc/apt/keyrings/packages.microsoft.gpg > /dev/null



Set readable permissions for the keyring:


sudo chmod 0644 /etc/apt/keyrings/packages.microsoft.gpg



Next, configure the repository:


echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" \

  | sudo tee /etc/apt/sources.list.d/vscode.list > /dev/null



Update the package index:


sudo apt update



Install Visual Studio Code:


sudo apt install code



After installation, verify that the command is available:


code --version



If the installation succeeds, the command displays version information and additional build details.


Repository configuration can change over time, so consult Microsoft's current Linux installation instructions if a command fails or the repository information differs from this guide.


Official installation instructions are available at:


https://code.visualstudio.com/docs/setup/linux


Avoid adding unfamiliar repositories or disabling package verification merely to make an installation succeed. Repository signing and package verification are important parts of maintaining a secure development environment.


5. Launch Visual Studio Code on Ubuntu


After installation, you can open VS Code in several ways.


Launch from the Application Menu


Open the Ubuntu application overview and search for Visual Studio Code or Code.


Select the application to launch the editor.


This method is convenient if you are new to the Linux terminal.


Launch from the Terminal


You can also run:


code



To open a specific directory, first navigate to the directory and then run:


cd ~/projects

code .



The dot represents the current directory.


VS Code opens that directory as a workspace, allowing you to browse its files and create new source files.


If you want to open a particular file, use:


code example.py



This command opens the specified file in the editor, creating or locating the file according to the application's behavior and the path you provide.


For a directory that contains multiple files, opening the whole folder is generally more useful than opening each file separately. The editor can then provide project navigation, search, and other workspace-related features.


If the code command is not recognized, confirm that VS Code installed correctly and that its command-line launcher is available through your shell's executable search path.


6. Explore the Visual Studio Code Interface


When VS Code opens for the first time, you will see an interface containing several important areas.


Activity Bar


The Activity Bar provides access to major features such as Explorer, Search, Source Control, Run and Debug, and Extensions.


Its position and appearance can vary depending on your settings and version.


Explorer


The Explorer displays the files and folders in the current workspace.


You can create new files, add directories, rename items, and organize a project without repeatedly entering filesystem commands.


For example, a small Python project might contain:


python-project/

├── main.py

├── README.md

└── requirements.txt



Each file serves a different purpose. The Python file contains program logic, the README explains the project, and the requirements file can document third-party Python dependencies.


Editor Area


The editor area is where you write and modify source code.


VS Code automatically recognizes many common file extensions and applies suitable syntax highlighting.


You can open multiple files in tabs and split the editor to view related files simultaneously.


Integrated Terminal


The integrated terminal gives you access to your shell within the editor.


Open it from the Terminal menu or use the default keyboard shortcut, commonly Ctrl + `.


On some keyboard layouts, the exact key combination may differ.


You can run commands such as:


pwd

ls

python3 --version

git --version



The integrated terminal uses your system's available shell and tools. It does not automatically provide a compiler or interpreter that has not been installed.


Status Bar


The status bar displays useful information about the active file and editor configuration. Depending on the file and installed extensions, it may show the programming language, line and column position, indentation settings, and diagnostic information.


Understanding these interface elements makes it easier to navigate projects and use the editor efficiently.


7. Create Your First Programming Project


Let's create a small Python project to test your installation.


First, verify that Python 3 is available:


python3 --version



If the command is missing, install Python using Ubuntu's package manager or follow the official Ubuntu documentation for your release.


Create a project directory:


mkdir -p ~/projects/hello-python

cd ~/projects/hello-python



Open the directory in VS Code:


code .



In the Explorer panel, create a new file named hello.py.


Add the following code:


def main():

    name = input("What is your name? ")

    print(f"Hello, {name}! Welcome to Ubuntu programming.")


if __name__ == "__main__":

    main()



Save the file.


This small program defines a function named main, asks the user for a name, and displays a greeting.


The condition at the bottom ensures that the function runs when the file is executed directly as a program.


To run the program, open the integrated terminal and execute:


python3 hello.py



Enter your name when prompted.


You should see a greeting containing the name you entered.


If the program works, you have successfully created and executed a Python script from a VS Code workspace on Ubuntu.


This exercise also demonstrates an important distinction: VS Code is the editor, while Python is the interpreter that executes the program.


For more advanced Python development, you may want to create a virtual environment and install the official Python extension.


8. Install Useful VS Code Extensions


One of VS Code's greatest strengths is its extension marketplace.


Extensions add language-specific features and integrate external tools into the editor. However, installing every available extension is unnecessary and can make your environment harder to manage.


Start with extensions that support the languages and workflows you actually use.


Python Extension


The official Microsoft Python extension adds Python-specific editing features and supports debugging and interpreter selection when the relevant components are configured.


It is particularly useful for beginners learning Python on Ubuntu.


C/C++ Extension


The Microsoft C/C++ extension provides language features such as IntelliSense and debugging integration.


You will still need an appropriate compiler, such as GCC, and a compatible debugger when developing native C or C++ applications.


ESLint


ESLint helps identify and enforce rules for JavaScript and TypeScript code in supported projects.


It is most useful when your project is configured with the corresponding ESLint tooling.


Prettier


Prettier is a code formatter that can automatically apply consistent formatting to supported languages.


It helps keep code readable across a team or project.


GitLens


GitLens adds Git-related insights and navigation features. It can help developers inspect file history and understand changes.


VS Code already includes built-in Git integration, so GitLens is optional.


How to Install an Extension


Open the Extensions view in the Activity Bar.


Search for the extension by name, verify its publisher and details, and select Install.


You can also install extensions from the terminal using the command-line interface.


For example:


code --install-extension ms-python.python



This command requests installation of Microsoft's Python extension.


To list installed extensions, run:


code --list-extensions



Only install extensions you trust. Extensions may have access to project files and can execute code, so review the publisher, permissions, and maintenance history when selecting third-party tools.


9. Configure VS Code for Python Development


If Python is your main programming language, a few configuration steps can improve your workflow.


First, ensure Python is installed:


python3 --version



Next, create a virtual environment inside your project:


python3 -m venv .venv



If Ubuntu reports that the required venv module is unavailable, install the appropriate Python virtual-environment package for your distribution. On many Ubuntu installations, the package is named python3-venv.


Activate the virtual environment:


source .venv/bin/activate



Your terminal prompt may change to show the environment name.


Now install project-specific packages using the environment's Python interpreter and pip:


python -m pip install requests



Using a virtual environment helps keep project dependencies separate from system Python packages.


This separation is useful when different projects require different library versions.


Open the Command Palette using Ctrl + Shift + P and search for the Python interpreter selection command provided by the Python extension.


Select the interpreter associated with your project's .venv directory.


The exact displayed label may vary by extension version and system configuration.


When the correct interpreter is selected, VS Code can use it for relevant Python features and run configurations.


If the environment is not detected automatically, verify that it exists and that the selected interpreter points to the correct executable.


Avoid installing application dependencies globally with administrator privileges unless you have a specific reason. Project virtual environments generally offer better dependency isolation.


10. Use the Integrated Terminal Efficiently


The integrated terminal lets you run commands while keeping your source code visible.


This is particularly useful when learning Linux programming because you can edit a script, execute it, inspect the output, and make changes without switching between multiple windows.


For example, you can compile a simple C program.


First, check whether GCC is installed:


gcc --version



If GCC is missing, install the compiler toolchain using Ubuntu's package manager:


sudo apt update

sudo apt install build-essential



Review the package manager's proposed changes before confirming.


Create a file named hello.c:


#include <stdio.h>


int main(void)

{

    printf("Hello from Ubuntu and C!\n");

    return 0;

}



Save the file and compile it:


gcc -Wall -Wextra -o hello hello.c



Run the executable:


./hello



The program prints a greeting in the terminal.


This example demonstrates how VS Code can work with an external compiler.


The editor provides the interface for writing code, while GCC translates the source file into an executable program.


For larger projects, you can organize compilation commands in a Makefile, configure a build system such as CMake, or use suitable extensions to improve the development workflow.


11. Use Git with Visual Studio Code


Git is a version-control system that tracks changes to files and helps developers collaborate on projects.


VS Code includes built-in Git support, so you can inspect many changes without relying entirely on terminal commands.


First, verify that Git is installed:


git --version



If it is not installed, use Ubuntu's package manager:


sudo apt update

sudo apt install git



Configure your author name and email if you have not already done so:


git config --global user.name "Your Name"

git config --global user.email "you@example.com"



Replace the example values with the identity you want recorded in your Git commits.


These settings identify the author of commits; they are not the same as your Git hosting account's authentication credentials.


Inside your project directory, initialize a repository:


git init



Create a .gitignore file to exclude generated files and local environments:


.venv/

__pycache__/

*.pyc

.env



Do not commit secrets or credentials to a repository. If your project uses other generated files, add suitable patterns to the .gitignore file.


You can now use the Source Control view to review changes, stage selected files, and create commits.


Alternatively, use terminal commands:


git status

git add main.py README.md .gitignore

git commit -m "Add initial project files"



Change the filenames to match your project.


Git provides a history of your work and makes it easier to experiment without losing track of earlier versions.


For collaboration, you can connect the repository to a remote hosting service such as GitHub or another Git server. Authentication and remote configuration must be set up separately.


12. Debug Programs in Visual Studio Code


Debugging is the process of investigating a program to understand why it behaves incorrectly.


Instead of relying only on print statements, a debugger can pause execution at specific locations and allow you to inspect variables and the program's current state.


VS Code supports debugging through language extensions and external debugging tools.


For Python, install the official Python extension and open a Python source file.


Click in the gutter beside a line number to add a breakpoint. A breakpoint marks a location where execution can pause when the debugger reaches that line.


Open the Run and Debug view and select an appropriate debugging configuration when prompted.


Start the debugger and inspect the values shown in the Variables panel.


You can then step through the program, continue execution, or examine the call stack.


For example, consider this code:


def divide(a, b):

    return a / b


result = divide(10, 2)

print(result)



Set a breakpoint inside the divide function.


When the debugger pauses, inspect a and b to verify that they contain the expected values.


Change the second argument to zero in a separate test to investigate the resulting division error.


A debugger helps you understand program behavior at a particular moment, but it does not automatically identify every logical problem. You still need to reason about the intended behavior and test different inputs.


For compiled languages such as C and C++, debugging generally requires a compatible debugger and an appropriate build configuration. The editor alone does not provide every language's complete debugging toolchain.


13. Customize the Editor for Better Productivity


VS Code allows you to customize its appearance and behavior.


A comfortable editor setup can reduce distractions and make long programming sessions easier to manage.


Change the Theme


Open the Command Palette using Ctrl + Shift + P.


Search for the Color Theme command and select a theme.


You can choose a dark theme, a light theme, or an installed theme from the marketplace.


The choice is mostly personal preference, although consistent syntax highlighting can make code easier to scan.


Adjust the Font Size


You can change the editor font size in the Settings interface.


Alternatively, open the settings JSON file and add an appropriate value:


{

    "editor.fontSize": 14,

    "editor.tabSize": 4,

    "editor.wordWrap": "on"

}



This example sets a readable font size, configures four-space indentation, and enables word wrapping.


Adjust these values to match your display and coding preferences.


Some projects use two spaces for indentation, while others use four. Follow the language conventions and existing project's style when contributing to shared code.


Learn Useful Keyboard Shortcuts


Several default shortcuts are especially helpful:


Ctrl + P: Quickly open a file by name.

Ctrl + Shift + P: Open the Command Palette.

Ctrl + Shift + F: Search across the workspace.

Ctrl + /: Toggle line comments in many supported languages.

Ctrl + Shift + E: Open the Explorer view.

Ctrl + Shift + X: Open the Extensions view.

Ctrl + `: Toggle the integrated terminal on common keyboard layouts.


Shortcuts may vary with operating-system configuration, keyboard layout, and customized settings.


Learning a few shortcuts at a time is usually more effective than trying to memorize all of them at once.


14. Common Visual Studio Code Problems on Ubuntu


Even when VS Code is installed correctly, you may encounter problems related to permissions, dependencies, extensions, or project configuration.


Understanding the cause helps you avoid unnecessary reinstallation.


The code Command Is Not Found


If the terminal reports that code is unavailable, verify that the installation completed successfully.


Run:


command -v code



If no path is returned, check your installation method and confirm that the VS Code command-line launcher is available.


Close and reopen the terminal after making changes to your environment if necessary.


Python Is Not Detected


VS Code may not automatically select the interpreter you expect.


Check Python from the integrated terminal:


python3 --version



Then use the Python extension's interpreter selection command to choose the correct environment.


If you are using a virtual environment, confirm that its Python executable exists.


Extensions Fail to Install


Extension installation can fail because of network connectivity, proxy configuration, marketplace access, or compatibility problems.


Check the displayed error message and verify your internet connection.


Make sure the extension supports your installed version of VS Code.


Avoid downloading extension files from unknown websites simply to bypass installation problems.


Permission Errors Occur in Project Files


If you cannot modify a file, inspect its ownership and permissions:


ls -l filename



Replace filename with the relevant path.


Do not automatically solve every permission issue by running the editor as root. First understand why the file is not writable and correct the underlying ownership or permission configuration when appropriate.


Programs Run in the Wrong Directory


A script may fail when it assumes that the terminal is already inside the project directory.


Check the current directory:


pwd



Navigate to the intended project folder or configure your launch settings to use the appropriate working directory.


VS Code Becomes Slow


Large workspaces, resource-intensive extensions, and background language servers can affect performance.


Try disabling extensions you do not need, closing unrelated workspaces, and checking system resource usage.


If the slowdown began after installing an extension, temporarily disable it to determine whether it is contributing to the problem.


The Integrated Terminal Does Not Start


Check your terminal profile settings and ensure that the selected shell is installed and available.


On a standard Ubuntu desktop, Bash is commonly available at /bin/bash.


If a custom shell or terminal configuration is involved, inspect its settings before resetting the entire editor.


15. Security and Privacy Best Practices


A programming editor often has access to source code, configuration files, and terminal commands. This makes it important to follow basic security practices.


First, download VS Code from its official website or use Microsoft's documented repository installation procedure.


Second, install extensions only when you need them. Review their publishers, descriptions, and maintenance history.


Third, do not paste private access tokens, passwords, or production credentials into source files that may be committed to Git.


Use environment variables, appropriate secret-management tools, or other secure configuration mechanisms according to your project's requirements.


Fourth, avoid opening untrusted projects and blindly approving every task, extension, or command they suggest. Some development features can execute code or launch external programs.


Fifth, keep Ubuntu, VS Code, and relevant development tools updated.


Finally, remember that editor extensions and debugging tools may access files within your workspace. Use additional care when working with proprietary source code or confidential information.


These practices do not eliminate every security risk, but they help establish a safer development environment.


16. Is Visual Studio Code Good for Ubuntu Beginners?


Visual Studio Code is a strong option for beginners because it offers a simple starting point while supporting increasingly complex development workflows.


A new programmer can begin with one file and a few lines of Python or JavaScript. As skills develop, the same editor can support Git, debugging, formatting, testing, and project-specific tooling.


Its integrated terminal is especially helpful on Ubuntu because many development tasks involve Linux commands.


Beginners should nevertheless understand the tools behind their editor.


For example, installing the Python extension does not necessarily install Python itself. Installing a C/C++ extension does not automatically provide a compiler. Similarly, Git integration requires Git to be available on the system.


Learning how these components work together helps you solve problems instead of depending entirely on graphical interfaces.


VS Code is also not the only available code editor for Ubuntu. Depending on your preferences, you may prefer a

Comments

Popular posts from this blog

How to Install Python on Ubuntu and Build Your First Python Project

How to Install and Use Git on Ubuntu for Version Control