1

I have diploma thesis and follow steps from this manual: Building a Beowulf Cluster in just 13 steps.

I have a problem with step 11:

Now we'll define the path to MPICH for SSH. Run the following command:

sudo echo /home/mpiuser/mpich1/bin >> /etc/environment

But above command returns this output:

bash: /etc/environment: Permission denied

How to solve this problem?

wjandrea
  • 14,504

1 Answers1

1

Your command does not work because the redirection of the output (>/>>) is not performed by sudo. There are several ways to solve this. For example:

  • You can use pipe (|) and performed by sudo tee command with --append option:

    echo /home/mpiuser/mpich1/bin | sudo tee -a /etc/environment
    
  • Another approach is to run the entire command as sudo:

    sudo bash -c 'echo /home/mpiuser/mpich1/bin >> /etc/environment'
    

In result the content of /etc/environment will looks something like:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
/home/mpiuser/mpich1/bin

References:


EDIT 1:


However I think this new line in /etc/environment will do nothing by itself. To have some meaning this "path" must be appended to the value of $PATH envvar.

Ubuntu Documentation says that:

Variable expansion does not work in /etc/environment.

So to append /home/mpiuser/mpich1/bin to the value of $PATH, via single command, you can use this one:

cat /etc/environment | sed 's/\"$/:\/home\/mpiuser\/mpich1\/bin\"/' | sudo tee /etc/environment

Where: (1) cat /etc/environment will print the content of the file; (2) sed '...' will replace the last quote mark (") with :/home/mpiuser/mpich1/bin"; (3) sudo tee /etc/environment will rewrite the file.

In result the content of /etc/environment will looks something like:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/mpiuser/mpich1/bin"

Please, scroll to the end.

References:


EDIT 2:


I did a little research and found few advices like this:

However, if you need to set that environment variable for all users, I would still not recommend touching /etc/environment but creating a file with the file name ending in .sh in /etc/profile.d. The /etc/profile script and all scripts in /etc/profile.d are the global equivalent of each user's personal ~/.profile and executed as regular shell scripts by all shells during their initialization.

And this:

Please avoid modifing system files. Instead you should place an executable script in /etc/profile.d (scripts in here got executed for every user) to change $PATH value.

According to these advises, let's suppose that you want to create a file named mpich-path.sh which is placed in the directory /etc/profile.d/. This can be done by the command:

echo 'export PATH="$PATH:/home/mpiuser/mpich1/bin"' | sudo tee /etc/profile.d/mpich-path.sh

In result the content of the new file /etc/profile.d/mpich-path.sh will looks like this:

export PATH="$PATH:/home/mpiuser/mpich1/bin"

Logout and login back into the system and type echo $PATH to check the result.


EDIT 3:


I don't know about the other steps in the manual that you have follow, but apart from step 11, step 10 also does not seem completely clear.

This part:

export PATH=/home/mpiuser/mpich1/bin:$PATH    # assigns a new value and exports the variable
export PATH                                   # exports the variable

must be:

PATH=/home/mpiuser/mpich1/bin:$PATH           # assigns a new value
export PATH                                   # exports the variable

or just:

export PATH=/home/mpiuser/mpich1/bin:$PATH    # assigns a new value and exports the variable

And it will produce the same result as step 11. So this part is unnecessary.

The new thing here is this part:

LD_LIBRARY_PATH="/home/mpiuser/mpich1/lib:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH

But, maybe, it can be included into the file - /etc/profile.d/mpich-path.sh - who we created above.

pa4080
  • 30,621