It provides all the steps required to install Visual Studio Code or VSCode for C++ and C development on Ubuntu and getting started with C/C++ development using the Hello World Project.

How To Install Visual Studio Code For C++ On Ubuntu
How To Install Visual Studio Code For C++ On Ubuntu
September 13, 2019

Visual Studio Code or VSCode is a cross-platform, lightweight editor and became popular in a very short span. It provides support for several programming languages. It also supports plugin development and there are several community-driven plugins available for it.

In this tutorial, we will discuss how to install and prepare Visual Studio Code or VSCode for C++ or C development on the popular Linux distribution i.e. Ubuntu. It provides several features for C/C++ development including IntelliSense, Debugging, Code Browsing, etc. This tutorial provides all the steps required to install VSCode on Ubuntu 18.04 LTS, though the steps should be similar for other Linux systems.

Notes: It assumes that GCC is already installed on the system. You may also be interested in How To Install GCC On Ubuntu 18.04 LTS to install the latest GCC on the popular Debian based Linux distribution - Ubuntu.

Step 1 - Download Visual Studio Code

We can download Visual Studio from the official download page. It provides options for Ubuntu as shown in Fig 1.

VSCode Download

Fig 1

Click on the .deb Download Button to start the download. You can also download the gz file to install it directly without using the deb package. This tutorial provides steps to install VSCode using the Debian package.

Step 2 - Install Visual Studio Code

In this step, we will install the Visual Studio Code downloaded by us in the previous step. Double click the installer to execute it. It will show the installer screen as shown in Fig 2.

VSCode Install

Fig 2

Click on the Install Button to start installing VSCode. It will show installation progress as shown in Fig 3.

VSCode Install Progress

Fig 3

After successful installation, it will show the final screen as shown in Fig 4.

VSCode Install Finish

Fig 4

Now close the screen to complete the installation. Click on the Show Applications icon at the bottom right corner of Ubuntu 18.04. It should show Visual Studio Code as shown in Fig 5.

VSCode Application

Fig 5

You may add it to your Favorite Apps or create a desktop shortcut icon based on your preferences. Launch VSCode to start coding in C/C++. It will show the welcome screen as shown in Fig 6.

VSCode Welcome

Fig 6

Step 3 - Marketplace

You can see all the available plugins on the Marketplace dedicated for Visual Studio Code. Type C++ in the search box and click on the Search Button. The results should be similar to one as shown in Fig 7.

Visual Studio Code - C++ - Marketplace

Fig 7

We can also browse the available extensions within the IDE by clicking on View -> Extensions or press Ctrl + Shift + x. Enter C++ on the Search Box and hit Enter Key. It will show the same extensions list within the IDE as we saw on the Marketplace Page as shown in Fig 8.

VSCode - C/C++ - Extensions

Fig 8

Step 4 - Install Extensions

We will install the most important extensions as part of this tutorial. Also, make sure that you are using the most recent version of MinGW or Microsoft C++ compiler.

C/C++ is the most important extension having IntelliSense, debugging and code browsing. Every C or C++ developer must install C/C++ plugin distributed by Microsoft for Visual Studio Code. Another popular extension is C/C++ Compile Run to compile and run single C or C++ files. The other extensions can be installed based on the requirements. Install the extension as shown in Fig 9 and Fig 10.

VSCode - C/C++ - Extension

Fig 9

VSCode - C/C++ - Compile - Run

Fig 10

Also, install the Code Runner Extension as shown below.

VSCode - Code Runner

Fig - Code Runner

Step 5 - Getting started with C++ - Hello World

In this section, we will create our Hello World project i.e. HelloCPP project and write and execute the first program using Visual Studio Code.

Click on File -> Open Folder or press Cntrl + K and Cntrl + O to open the File Chooser to select the project folder. It will open the selected folder as highlighted in Fig 11.

VSCode - C/C++ - Folder

Fig 11

Now click on the New File Icon as highlighted in Fig 12.

VSCode - C/C++ - File

Fig 12

Enter the file name as hello.cpp and hit the Enter Key. It will create the C++ file as shown in Fig 13.

VSCode - C/C++ - File View

Fig 13

Update the file and write the first program to print Hello World as shown in Fig 14.

VSCode - C/C++ - File Update

Fig 14

Now right-click the file and choose the option Run to compile, build, and execute the program as shown in Fig 15 and Fig 16.

VSCode - C/C++ - File Run

Fig 15

VSCode - C/C++ - File Output

Fig 16

Step 6 - Getting started with C - Hello World

We can follow the same steps to create the file hello.c and update the program as shown in Fig 17.

VSCode - C - File

Fig 17

Now right-click the file and click on the Run option to compile, build, and execute it similar to C++ file as shown in Fig 18.

VSCode - C - Output

Fig 18

This is how we can install Visual Studio Code for C/C++ development. We have also written our first hello world program for both C and C++ and executed the programs within the editor.

Write a Comment

Click on the captcha image to get new code.
Discussion Forum by DISQUS