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)
Jun
  • 531
  • 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. – Mingye Wang 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. – Mingye Wang 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 02:02
  • mostly because it's the sysadmin's job, not yours...you shouldn't have to do their work, you should be free to focus on your research. – cas Oct 27 '15 at 02:10
  • btw, i've spent many years as a sysadmin in university environments. i always saw that part of my job as supporting the academic staff and post-grad students to do their work - that's what i was being paid to do. and i always preferred they ask me to install something for them than have to deal with the mess when they try it themselves and it doesn't work. – cas Oct 27 '15 at 02:13
  • @cas I nearly cried when see you comments, literally. I am not programmer myself, but this is very important for my research and will be more important later. Most of my time was to used to struggle through installation, configuration trouble shooting stuff. Definitely I would wish the sysadmin could be more supportive like you, cas. – Jun Oct 27 '15 at 04:53
  • @cas I would like to take advantage of your kindness, if I may. Could you advise me that would it be better to install R in the system, rather than in my home directory? I am asking that because, to my understanding, a lot of people use R with certain specific added-on packages, In my case, sometimes I even need to downgrade the version of R, so that I could use a specific package, which quite often lag behind the update of the latest version of R. Thanks very much. – Jun Oct 27 '15 at 05:00
  • Aside from pointing out that add-on packages can be installed in your home dir (e.g. see http://www.r-bloggers.com/installing-r-packages/), there's not much more to say. You've already mentioned the only really good reason (version compatibility) for installing R or whatever in your home dir. – cas Oct 27 '15 at 05:38
  • @cas I did not realise that I could actually install the add-on packages in the directories separated from that of R. Really appreciate that you could inform me about that! – Jun Oct 27 '15 at 06:44

2 Answers2

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!

Jun
  • 531
  • 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 01: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 02:00
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.

Jun
  • 531
Archemar
  • 31,554
  • 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. – Mingye Wang 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
  • is /user/ifrec/junhuang/Programme/bin/R executable ? does it work ? – Archemar Oct 26 '15 at 15:33
  • @Archemar, yes it works: [junhuang@idngs ~]$ /user/ifrec/junhuang/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)

    – Jun Oct 26 '15 at 15:34
  • @Dani_l, Sorry i did not get it in the beginning, but when I changed the order, still no difference... – Jun Oct 26 '15 at 15:45
  • @Arthur2e5 I did as you as well as other people suggested (sorry I did not get you idea in the beginning), but still could not make it work... – Jun Oct 26 '15 at 15:53
  • What exactly did you try? If you only changed the file, you need to source it, or else logout and login again. To expedite issues, what does PATH="$HOME/Programme/bin" R do ?(note the space between bin and R) – Dani_l Oct 27 '15 at 05:36
  • @Dani_l, the comments here lost their format so they looks confusing. Could you check the answer I wrote myself (adding answer oneself looks silly, but that seems the only way to keep the format. )? if I left out some necessary details, please let me know. Essentially I what I did was following your and other's suggestions to change the order of system R and my own R and use .cshrc file instead of .bash_profile. – Jun Oct 27 '15 at 06:33
  • @Jun seems like the problem is solved, next time make sure to mention your shell environment in the original question, and possibly the contents of /etc/issue to help others understand your environment faster. – Dani_l Oct 27 '15 at 08:59
  • @Dani_l. Sure! Sorry for leaving out important information. Again thanks! – Jun Oct 27 '15 at 15:38