Question: After installing R and RStudio in Ubuntu 16.04 with the following code:

```
sudo apt-get update
sudo apt-get install r-base
sudo apt-get install r-base-dev

```

and

```
sudo apt-get install gdebi-core
wget https://download1.rstudio.org/rstudio-1.0.143-amd64.deb
sudo gdebi rstudio-1.0.143-amd64.deb

```

I am trying to install packages and I am getting errors in R console like

```
install.packages("fGarch")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning in install.packages :
  'lib = "/usr/local/lib/R/site-library"' is not writable
```

As I am new in Linux I do not know in which directory install the R packages.
I am not sure whether this is the problem or if I did any mistake on the installation. Can anyone help me with this issue? Thanks in advance.

Answer: 
If you want to install the R add-on package for *all users* to `/usr/local/lib` you'll need to give R super-user privileges to create files there. To install R add-on packages as super-user run:

```
sudo R CMD INSTALL <PACKAGES…>

```

where you replace `<PACKAGES…>` by the names of any number add-on packages to install.

---

If you want to install a package for *yourself only* you don't need to give R super-user privileges but you need to specify an installation target. One convenient way to do this is with an environment variable:

```
export R_LIBS_USER=<PATH>

```

where you replace `<PATH>` by the path to a directory for your user-specific R packages. I recommend `~/.local/lib/R/site-library`. Now you can install the packages:

```
R CMD INSTALL <PACKAGES…>

```

You'll need to assure that this environment variable is set before starting R or it won't find the packages installed to that location. The best option would be to append the above `export` command to the file `~/.profile`. See [Environment Variables](https://help.ubuntu.com/community/EnvironmentVariables#A.2BAH4-.2F.profile) for more.
Try opening up R through the terminal under **sudo**. This will require you typing in your password and will allow you to give permissions to write over files in your system. [Picture](https://i.stack.imgur.com/ceVfa.png)

Edit: See picture for clarity