Q:

I cant install the forecast package

I have installed the latest version of R but I can't install the package forecast. When I try, I get an error:

No such file or directory Error in install.packages : cannot open the
  connection

A:

The following may be of use: 
It looks to me like you need to change your CRAN access mechanism in RStudio. I am not sure which OS you are running RStudio on, so here is a breakdown of the how by OS. I hit the same issue on Centos 7, and this is how I resolved it.
Windows
utils::setInternet2(TRUE)
options(download.file.method = "internal")

Note that setInternet2(TRUE) is the default value in RStudio however is not for R GUI. If you don’t want to use setInternet2(TRUE) on Windows then the only other way to configure secure downloads is to have the “wget” or “curl” utility on your PATH as described for OS X and Linux below.
OS X
options(download.file.method = "curl")

Linux
options(download.file.method = "wget")

Note that the “curl” and “wget” methods will work on any platform so long as the requisite binary is in the system PATH. The recommendations above are based on the fact that “curl” is included in OS X and “wget” is included in most Linux distributions.
Proposed Solution
I use this on Centos 7, to reconfigure my CRAN setup. I have this added to my .Rprofile, you can try by running at the R prompt.
options(download.file.method = "wget") # <- for MacOSX use curl

local({
     r<- getOption("repos");
     r["CRAN"] <-"https://cran.rstudio.com/"
     options(repos=r)
}) 

> install.packages("forecast")

Explanation:
When R transfers files over HTTP (e.g. using the install.packages or download.file function) a download method is chosen based on the download.file.method option. There are several methods available and the default behaviour if no option is explicitly specified is to use R’s internal HTTP implementation. In many circumstances, this internal method will not support HTTPS connections so you’ll need to override the default.
ref: https://support.rstudio.com/hc/en-us/articles/206827897-Secure-Package-Downloads-for-R

