4

Although I thought I'm close to be professional in Linux but apparently I'm still a beginner. When I login to a server, I need to use the latest version of R (a statistical software). R is installed in 2 places. When I run the following command

which R

I get

/usr/bin/R

and then

R --version
R version 2.15.2 (2012-10-26) -- "Trick or Treat"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-redhat-linux-gnu (64-bit)

apparently it is an old version and I know the last version of R is installed in

/usr/local/bin/R

I know I should change the path. Am I right? and How?

MTT
  • 5,113
  • 7
  • 35
  • 61

2 Answers2

5

If you put the following in your .bashrc you will get the newer R first, because bash will search that directory before the other one.

export PATH=/usr/local/bin:$PATH

Update: Since the OP is apparently using tcsh, the correct way to set the path is to use setenv inside ~/.profile or ~/.tcshrc.

setenv PATH /usr/local/bin:$PATH
merlin2011
  • 71,677
  • 44
  • 195
  • 329
4

It's fine to have multiple versions of interpreters/compilers co-existing in different paths (I have 3 different versions of python in my /usr/local/bin). Just create an alias in your .bashrc file in your home directory:

alias R="/usr/local/bin/R"
Gillespie
  • 5,780
  • 3
  • 32
  • 54
  • Thanks for the answer. The problem is that I do not have .bashrc . I only have .profile. – MTT Feb 05 '15 at 01:21
  • Did you try adding the alias to `.profile`? It's probably loaded when you first start up a shell. Otherwise, if you are using bash you can create a new `.bashrc` file with the command `touch .bashrc`. If you are using another shell like `ksh` you can add the alias in `.ksh` in the home directory. – Gillespie Feb 05 '15 at 01:34
  • I tried to add alias to .profile but it did not solve the problem. Here is the .profile: PATH=/usr/local/mpich/bin:/usr/local/pbs/bin:/usr/local/intel/bin:/usr/local/maui/bin:/bin:/usr/bin:$HOME/bin:/usr/local/bin:/usr/ucb alias R="/usr/local/bin/R" – MTT Feb 05 '15 at 02:20
  • I also created .basrc and added alias to it. Still does not work. – MTT Feb 05 '15 at 02:22
  • Try adding the alias to a line of its own. Don't put it in with the path line. Also, what shell are you using? Run the command `ps -p $$` to print your current shell. – Gillespie Feb 05 '15 at 02:30
  • Actually I added alias on its own line. – MTT Feb 05 '15 at 02:33
  • PID TTY TIME CMD 20585 pts/2 00:00:00 tcsh – MTT Feb 05 '15 at 02:34
  • Looks like you are using `tcsh`. In that case, you'll need to create a file in your home directory called `.tcshrc`, add the alias line, then close all of your shells and then open them again. – Gillespie Feb 05 '15 at 02:37