2

I would like to install “R” into my directory in the server,

Here is what I have tried following the guidance here: Install R in my own directory

wget http://cran.rstudio.com/src/base/R-3/R-3.2.2.tar.gz
tar xvf R-3.2.2.tar.gz
cd R-3.2.2
mkdir ~/Programme # create a folder called “Programme” for R
./configure --prefix=$HOME/Programme
make && make install

Then when I tried set the PATH for R:

    vi .bash_profile #create a .bash_profile 

#set PATH so it includes user's private bin if it exists  

    if [ -d "HOME/bin" ];then   
        PATH="$HOME/bin:$PATH"  
    fi  
    PATH="$PATH:$HOME/Programme/bin/"  

but when I use which R still I am using the R installed for the whole server, instead of the R in my directory. the problem is if I could not use my own R, then I could not install other R packages.

Could anyone solve this problem? Thanks very much.

I tried set the .bash_profile into this way:

#set PATH so it includes user's private bin if it exists 
if [ -d "$HOME/bin" ];then
    PATH="$HOME/bin:$PATH"
fi
PATH="$HOME/Programme/bin/:$PATH"

but still could not get it worked. the R in my directory can be executed:

[myusername@host ~]$ ~/Programme/bin/R

R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
  • Just a side note, [ -d "HOME/bin" ] should be [ -d "$HOME/bin" ]. And it's way to process PATH -- prepending so it get checked first -- is just what you need. – Arthur2e5 Oct 26 '15 at 14:51
  • I added the "$"in front of "HOME", quit the server, re login, checked by "which R", still "/usr/bin/R", the system R – Jun Oct 26 '15 at 15:04
  • Its way (oops, sorry for that extra ' in the first reply), not all its code. For you it should look like …… Well, just like Archemar's solution. – Arthur2e5 Oct 26 '15 at 16:59
  • If you haven't already done so, the first thing you should do is ask the systems administrator(s) to install R as a system-wide tool so that all users can use it. You shouldn't have to install and maintain common tools like R yourself, that's the sysadmin's job. – cas Oct 26 '15 at 21:15
  • @cas thank you, cas. but I am not sure that would be the best option.I do not want to use the system R is because I do not bother admin every time when I try to install a new package. let me know if I was wrong. As you could tell, I am quite inexperienced. – Jun Oct 27 '15 at 2:02
0

R is in default $PATH, put you own first:

 PATH="$HOME/Programme/bin/:$PATH" 

(assumming $HOME is /user/institute/username )

  • do not use PATH="$PATH:/user/institute/username/Programme/bin/:$PATH" this will still put /usr/bin before /user/institute/username/Programme/bin.

you set

if [ -d "HOME/bin" ];then   
    PATH="$HOME/bin:$PATH"  
fi

This might be usefull for any programs you have in $HOME/bin, but not for R.

  • You might need some additionnal environnement variable, I'll check. – Archemar Oct 26 '15 at 14:47
  • With his --prefix declared with some $HOME, I think using PATH="$HOME/Programme/bin:$PATH" is better. – Arthur2e5 Oct 26 '15 at 14:53
  • #set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ];then PATH="$HOME/bin:$PATH" fi PATH="$PATH:/user/ifrec/junhuang/Programme/bin/:$PATH" ~ ~ ~ I modified my .bash_profile, but still I can not use R in my directory. – Jun Oct 26 '15 at 15:01
  • 1
    @Jun As others already told you, it should be PATH="$HOME/Programme/bin:$PATH and not PATH="$PATH:whatever", so your R gets in front of system installed R. – Dani_l Oct 26 '15 at 15:09
  • @Archemar [junhuang@idngs bin]$ ls R Rscript [junhuang@idngs bin]$ pwd /user/ifrec/junhuang/Programme/bin # it is in $HOME/Programme/bin – Jun Oct 26 '15 at 15:15
1

Thank you, everyone! You guys are right, I should put the my own R' path first.

And I am sorry that I made another mistake.

I was using C shell!

I realised that when I "source" the .bash_profile, I got

"if:Expression Syntax error"

I searched it, found: https://stackoverflow.com/questions/14440105/bashrc-if-expression-syntax-error someone indicated that:"'if: Expression Syntax' is not an error bash would give you. Perhaps your shell is not bash. " So I checked my shell :

"echo $0"

got:

"-csh #!!!"

Then I created .cshrc:

{setenv PATH $HOME/Programme/bin/:$PATH}

And then logout and login again. Problem solved!

  • 1
    Oh! Come on !! Are thou jokin ' ? – Archemar Oct 26 '15 at 18:33
  • Yeah, I know it looks jokingly fool. but that was how fool I was... – Jun Oct 27 '15 at 1:55
  • Your suggest certainly helped me, put the path in the right order, and make me feel sure the "content" of PATH should be right and think about other possibilities. please forgive newbies... – Jun Oct 27 '15 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.