How to install R with compiling the source code in the user directory without root permission, such as on an ssh server (Linux)


Introduction

In this article, I will describe how to compile source code and install software such as R on a user directory when root permissions are not granted, such as on a Linux SSH server.
The advantage of this method is that you can create an environment without referring to the root directory without permission when installing or loading packages, so you can create it from the vanilla state. On the other hand, for the above reason, when installing certain packages, you need to separately install and pass through the C library libpng, which is a library for encoding and decoding PNG. This is a point that I personally felt could be a trap.
日本語版 : https://qiita.com/drafts/7c15381c31693e2ec8d4/edit

Environment

・CPU : Intel Xeon Gold 6248 (Cascade Lake) |
・OS : Red Hat Enterprise Linux 7.6 |
・shell : Bash(default shell = csh)|

1. Install and Activate R

First, after downloading the R source code from the web, we will describe the steps to pass the PATH. 1.
1. install the compiler with wget
Save the source code in the directory where you want to install it using the following command. This will be an example for R-4.0.4.
wget https://cran.ism.ac.jp/src/base/R-4/R-4.0.4.tar.gz
2. unzip with the tar command and migrate to the directory
tar xzvf R-4.0.4.tar.gz
cd R-4.0.4/

3. Execute configure under the --prefix directory. The most important operation is to specify the installation directory as the user directory using --prefix. If you do not do this, /usr/local, which you do not have permissions to, will be specified by default, and you will not be able to install.
As an example, here is how to install to the current directory.
pwd
. /configure --prefix=paste the current directory displayed by pwd

4. If an error occurs, follow the instructions to add --use~ as an argument and run again.
5. Construct the environment with make command
make
make install

6. After this, you can use bash. /R_4.0.4/bin/ in bash. /R will start R. If necessary, pass the environment variables according to the following steps.
7. Add the environment variable to the ./bashrc file under the user's home directory. /bashrc under the user's home directory.
export PATH="--prefix path/bin:$PATH" .
. The environment variables listed in /bashrc will be applied the next time you start up bash, so please restart the console or apply them with the following command.
`source .bashrc.

2.Install libping

The operations described so far alone do not install the image display package for linux, so many of the R packages cannot be installed. (had non-zero exist will be returned).
In the same process, we need to separately install libpng written in C, which is a library to encode and decode PNG.
9. Get the source code from wget https://cfhcable.dl.sourceforge.net/project/libpng/libpng16/1.6.34/libpng-1.6.34.tar.xz
10. unpack tar xf libpng-1.6.34.tar.xz
11. cd libpng-1.6.34/ from directory
12. compile . Specify /configure --prefix
13. make check
14. sudo make install
15. export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" and pass the environment path to .bashrc
16. open R and install.packages()
Now that R can handle PNGs, it is expected to be able to install various packages. In this way, the number of packages that can be handled will increase as you add the necessary software, such as igraph for network analysis.