Skip to content

Linux Native for Programming C++

Setting up VS Code under Linux by following this video by Dr. Brian, or this guide from Microsoft.

Install Tools in Linux

  1. Open a Linux terminal run the command to update the package manager:
    sudo apt update
    (Enter you password as needed; it won't show anything as you type.)
  2. Install C++ compiler and debugger:
    sudo apt install g++ gdb
    Select yes if asked to confirm.
  3. Verify tools installed with the following commands in the Ubuntu terminal:
    g++ --version
    gdb --version
    • You'll need GCC 14 or higher to support the c++23 spec for println(). You may need Ubuntu 24.10 or Debian 13 or higher to get GCC 14 by default. Ubuntu 24.04 offers it as the g++-14 package. If you are running Ubuntu 24.04, you can install the newer version of GCC with:
      sudo apt install gcc-14 g++-14
  4. Create a CMPT130 directory for your work:
    mkdir cmpt130
  5. Optional: Add cmpt130 to a Git repo to back it up.

Install VS Code

Follow these steps to configure VS Code, taken from this Microsoft guide.

  1. Download and install VS Code.
  2. File > Open Folder; select cmpt130 from the list, click OK.

Now, each time you want to work on CMPT 130 C++ code, open VS Code. It should re-open your cmpt130 folder for you.

Writing Your C++23 Code

Proceed now to configure VS Code for C++23 and write your code.

Go To Writing Your C++23 Code Configure VS Code and select C++23 when compiling / running / debugging.
  • If #include <print> is underlined in red, it may mean that your system is defaulting to the incorrect version of G++.
    • First ensure you gave G++ version 14 or higher installed.
      sudo apt install g++-14 gcc-14
    • In VS Code, go to File > Preferences > Settings; select Extensions > C/C++ > IntelliSense.
      Scroll down to C_Cpp - Default: Compiler Path; select "Edit in settings.json"
      Set line to:
      "C_Cpp.default.compilerPath": "/usr/bin/g++-14"

Submitting Code from Linux Native

With a native install under Linux, all your code is stored on your personal computer in the cmpt130 folder that you created to start with. Each time you launch VS Code you'll need to re-open that folder (if not done automatically).

To submit your C++ code (.cpp files) for labs or assignments, use your normal web browser and upload your files from the cmpt130 folder.

Note: Since the files are on your home computer, it's essential that you backup your files. I recommend having an automatic backup program for these files. Almost every student experiences a file loss some time throughout their degree (I did, twice!); have a backup!

Pushing your code to a Git repository is another great option (beyond the scope of this guide).