Installing a R package in linux

I am a big fan of the linux OS and I run R on my lubuntu system. A problem I observe is with installing packages. A package in windows gets easily installed by the command:

install.packages('packageName') 

This is because Windows just gives programs permission to install whatever they want by default. Linux being a bit stricter, doesn’t let programs do that. A typical error looks like:

installation of package ‘curl’ had
non-zero exit status 2: In install.packages("devtools") :  
installation of package ‘httr’ had non-zero exit status 3: In
install.packages("devtools") :   installation of package ‘rversions’
had non-zero exit status 4: In install.packages("devtools") :  
installation of package ‘devtools’ had non-zero exit status

Even if the install.packages command would work in R, in a later instance of a R session, the package doesn’t load.
Hence, the following commands in the terminal, ensures fool-proof that a package does get installed properly.

$ sudo su  
$ R
> install.packages('packageName', repos='http://cran.rstudio.com/')
# replace packageName with the package you want
>q()
$ exit