0

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

  • 1
    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 as execve() look for commands when you call them by name. That's why doing ls 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 for g++ 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
  • 3
    Most likely it is a Windows question. – Pilot6 Feb 14 '19 at 18:25
  • @Pilot6 Let's not assume There's been no indication of Windows things yet – Sergiy Kolodyazhnyy Feb 14 '19 at 18:29

1 Answers1

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;
 }
  • It's more accurate to say, that on Ubuntu the location to which g++ installs is added to PATH already, not that it's globally unnecessary under Linux. In case of ping 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