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,236
  • 4
  • 48
  • 98
Stanislav
  • 11
  • 4
  • "Permission denied" or "No such file or directory"? Did you check manually if the file is there? If the file is there you must use echo /home/mpiuser/mpich1/bin | sudo tee -a /etc/environment. – pa4080 Mar 03 '17 at 11:59
  • Now I have this error: bash: /etc/environment: Permission denied

    I have folder mpich1 in /home/mpiuser

    – Stanislav Mar 03 '17 at 12:10
  • Which command gives this error - sudo echo /home/mpiuser/mpich1/bin >> /etc/environment or echo /home/mpiuser/mpich1/bin | sudo tee -a /etc/environment? – pa4080 Mar 03 '17 at 12:15
  • First command, when I put second command I have this output: /home/mpiuser/mpich3.2/bin – Stanislav Mar 03 '17 at 12:17
  • Please type sudo cat /etc/environment and check your string is added correctly. – pa4080 Mar 03 '17 at 12:19
  • I have this output:

    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

    /home/mpiuser/mpich1/bin

    – Stanislav Mar 03 '17 at 12:48
  • It looks exactly like what you want to do, isn't it? – pa4080 Mar 03 '17 at 12:52
  • Check this site: https://www.linux.com/blog/building-beowulf-cluster-just-13-steps

    I don't know what to put in environment file, maybe step 10?

    – Stanislav Mar 03 '17 at 12:54
  • I think step 11 is not correct. Maybe, you need to append /home/mpiuser/mpich1/bin to the value of PATH envvar, and the content of /etc/environment must be: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/mpiuser/mpich1/bin" You can edit the file manually or according above example this command could do that: sudo cat /etc/environment | sed 's/\"$/:\/home\/mpiuser\/mpich1\/bin\"/' | sudo tee /etc/environment. – pa4080 Mar 03 '17 at 13:19
  • What to do now? Step by step. I don't put nothing in /etc/environment. This file by default. I need only define the path to MPICH for SSH. – Stanislav Mar 03 '17 at 13:26
  • I updated my answer with more detailed explanations. – pa4080 Mar 07 '17 at 20:37

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
  • 29,831