If you are running macOS or Ubuntu and have installed R in for example in /opt/local64/R/3.1.1/ and have /opt/local64/R/3.1.1/bin in your path would like to write scripts that use this location, and any other location where you install new versions of R, you may use /bin/env to start R.
The general idea in Unix is that the operating system and the packaging system install software in /bin and /usr/bin. The user install for a local system manually in /usr/local/bin. Shared software over a distributed file system (NFS, Lustre, CepFS..) usually resides in /sw /opt /srv. A packaging system external to the OS (like MacPorts) usually resides in /opt/local.
$ which R /opt/local64/R/3.1.1/bin/R $ cat >test.r <<EOF > #!/bin/env Rscript > > print('hello') > > EOF $ cat test.r #!/bin/env Rscript print('hello') $ chmod +x test.r $ ./test.r  "hello" $