I need to "set up the environemnt so that the location of g++ is available from the PATH? WHat does that mean? I am new to computer science hence the jargon is still a bit confusing
Asked
Active
Viewed 424 times
1 Answers
1
You are probably reading instructions for setting up GCC on Windows. While Linux does have environment variables, including the PATH
variable, it's not needed to add GCC to your PATH
since it will be available by default.
Simply install GCC which includes the g++
compiler:
sudo apt install build-essential
This will install GCC and other common tools for building C++ code such as make
. If for some reason you want to only install GCC you can do:
sudo apt install gcc
In either case you will see that both gcc
and g++
commands are available and can compile a basic hello world like this:
g++ hello.cpp
Where hello.cpp
contains something like:
#include <iostream>
int main() {
std::cout << "Hello" << std::endl;
return 0;
}

Kristopher Ives
- 5,509
-
It's more accurate to say, that on Ubuntu the location to which
g++
installs is added toPATH
already, not that it's globally unnecessary under Linux. In case ofping
command, openSUSE for instance has no/sbin
in PATH while Ubuntu does ( source ). But otherwise +1'ed, good answer – Sergiy Kolodyazhnyy Feb 14 '19 at 18:35
PATH
is an environment variable, usually set via shell config files. It's a colon-separated list of directories, and it is where shell or syscalls such asexecve()
look for commands when you call them by name. That's why doingls
instead of/bin/ls
works in shell. If that's your question, it's a duplicate of https://askubuntu.com/questions/60218/how-to-add-a-directory-to-the-path As forg++
compiler , you need to install it first, so the question is "Have you installed g++ in the first place ?" – Sergiy Kolodyazhnyy Feb 14 '19 at 18:22