-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,321
  • 1
  • 5
  • 28
  • 1
    "_What is it I need to do?_" - you need to complete the instructions. "_Why is this step necessary?_" -because without this step the openmpi commands won't be executable directly from your command line – roaima Nov 26 '22 at 15:59
  • Does this answer your question? [How to correctly add a path to PATH?](https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path) – NotTheDr01ds Nov 26 '22 at 16:01
  • 3
    `export PATH` must start from a new line. – Artem S. Tashkinov Nov 26 '22 at 16:06
  • Does This step work to indicate for my terminal where my OpenMPI is? – Everson Gomes Nov 26 '22 at 16:20
  • Do I need to go for some specific folder to put this line? – Everson Gomes Nov 26 '22 at 16:22
  • 1
    @EversonGomes The message explicitly tells you to edit `.bashrc` which is located in your home directory. – doneal24 Nov 26 '22 at 16:42
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 26 '22 at 16:45
  • 1
    @ArtemS.Tashkinov, actually, it works like that, too. In all other shells I tried but zsh. Though it is an odd way of putting it. ([Variable assignments before special builtins affect the current execution environment.](https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/V3_chap02.html#tag_18_09_01) Though the spec does say it's unspecified "Whether or not export attributes gained as a result of the variable assignments persist after the completion of the special built-in utility" which somewhat sounds there might be a potential gotcha.) – ilkkachu Nov 26 '22 at 20:03
  • @ilkkachu: In Artem S. Tashkinov’s defense, the message says “add the following two lines”, so it looks like the OP transcribed the message by hand (rather than copy & paste) and made an error. Or perhaps they misused the “blockquote” function in the Stack Exchange editor. The reference to `./bashrc`, and the ``$which mpirun`` (rather than ``$ which mpirun``), also suggest transcription errors (although, yes, the message *might* really look like that). – G-Man Says 'Reinstate Monica' Jan 18 '23 at 18:34
  • @G-ManSays'ReinstateMonica', ooh, I missed the `./bashrc` part. Anyway, I think I was just surprised that it _did_ work when I tried it. – ilkkachu Jan 18 '23 at 19:08

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
  • 1
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