-4

I finished installing OpenMPI, and at the end of the process it asks to do the following:

Then openmpi is installed at the directory indicated by prefix. Next,
add the following two lines to your ./bashrc file, which is located
at your home directory.

PATH=$PATH:/usr/local/openmpi-3.0.0/bin export PATH

When you open the terminal window next time, you can use openmpi. Make it sure by typing

$which mpirun

What is it I need to do? Why is this step necessary?

NotTheDr01ds
  • 3,547

2 Answers2

0

The PATH is a shell variable which will execure commands in your shell without giving full path to the installation location. To know your current command paths you can run the following command in shell

# echo $PATH

You have installed the software on a different path /usr/local/openmpi-3.0.0/bin , your openmpi full command path is /usr/local/openmpi-3.0.0/bin/openmpi

So if you add the folder /usr/local/openmpi-3.0.0/bin to your PATH variable you can simply execure the command as .

# openmpi

Otherwise you need execure it as

# /usr/local/openmpi-3.0.0/bin/openmpi
sherin
  • 101
0

A couple of things: First, like the commenter @Artem S. Tashkinov says, (in some shells) the export PATH needs to be on a new line since it's a separate command. It's saying set the new PATH as an environment variable. An environment variable is a variable (a dynamic value) which is used not only by one program, but the whole environment. As a simplification, think environment = shell (corrected thanks to ilkkachu).

Secondly, to more directly answer your question, $PATH is an environment variable which stores the locations of executables (programs). You are simply appending /usr/local/openmpi-3.0.0/bin to $PATH, so that if you type mpirun in a terminal, the shell knows it lives in /usr/local/openmpi-3.0.0/bin and can run it. The part before the colon is the contents of $PATH already; the colon means 'append what follows to what preceded'; and the /usr/local/openmpi-3.0.0/bin is the thing to append.

You may ask, why do I need the dollar? The simple answer is that the shell references variables that have already been defined with a $. For example, if I run:

NAME='BOB'

echo $NAME

the shell would print BOB, whereas

echo NAME

would result in the shell printing NAME.

Finally, you don't want to just change $PATH to the home of your executable (as opposed to appending), otherwise the system wouldn't know where other programs live.

  • Saying the "environment" is the whole system is just wrong: exported variables set in one shell are only visible to subsequent child processes of that same shell, not the whole system, not even all new processes of the same user. (and as an aside, FOO=bar export FOO works in most shells without the newline too.) – ilkkachu Nov 26 '22 at 20:06
  • @ilkkachu, yep, you're right. I meant "think environment=shell". I've corrected it accordingly. I also didn't know about the new line thing either, so thanks :) – notastringtheorist Dec 04 '22 at 19:52
  • (Not that I'd use foo=bar export foo, mind you. It looks odd and confusing. And doesn't work in zsh. Mostly I mentioned it on the off chance that it was actually like that in the source the OP used. But on a second read, it does say "following two lines", so maybe it is indeed just miscopied.) – ilkkachu Dec 04 '22 at 19:55