How to set PATH for R installed in my directory

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

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   

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

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

[[email protected] ~]$ ~/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)

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 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:
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”


“-csh #!!!”

Then I created .cshrc:

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

And then logout and login again.
Problem solved!

Solution 2

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


(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   

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

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply