# Can't get a functioning install with stan 2.21.0 on windows 10 and R v4.0.2 -demo can't find rtools - solved!

**URL:** <https://discourse.mc-stan.org/t/cant-get-a-functioning-install-with-stan-2-21-0-on-windows-10-and-r-v4-0-2-demo-cant-find-rtools-solved/18462>\
**Category:** Interfaces\
**Created:** [October 7, 2020, 11:26am UTC](https://discourse.mc-stan.org/t/cant-get-a-functioning-install-with-stan-2-21-0-on-windows-10-and-r-v4-0-2-demo-cant-find-rtools-solved/18462 "2020-10-07T11:26:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GustafRydevik](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/gustafrydevik/32/1328_2.png) [@GustafRydevik](https://discourse.mc-stan.org/u/GustafRydevik)\
**Post date:** [October 7, 2020, 11:26am UTC](https://discourse.mc-stan.org/t/cant-get-a-functioning-install-with-stan-2-21-0-on-windows-10-and-r-v4-0-2-demo-cant-find-rtools-solved/18462/1 "2020-10-07T11:26:19Z")

</div>

I 'm struggling to get Stan to run on my computer at the moment

I’ve removed the rstan package and installed as per [https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started](https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started)  
I’ve installed rtools40. When running rstan::stan\_demo(1), I get the following error message:  
Error in compileCode(f, code, language = language, verbose = verbose) :  
sh: C:/Rtools/mingw\_64/bin/g++: No such file or directorymake: \*\*\* [C:/PROGRA~1/R/R-40~1.2/etc/x64/Makeconf:229: file130c67f5cc3.o] Error 127  
In addition: Warning message:  
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :  
‘C:/rtools40/usr/mingw\_/bin/g++’ not found  
Error in sink(type = “output”) : invalid connection

I had some issues with having remains of the previous version of rtools in my path, but cleaned this up, before reinstalling, and still have the above error. I cant find the paths in the above complaints when running Sys.getenv()[‘PATH’] either. Here’s the output

```

PATH C:\rtools40\usr\bin;C:\Program
                               Files\R\R-4.0.2\bin\x64;C:\Program Files (x86)\Intel\iCLS
                               Client;C:\Program Files\Intel\iCLS
                               Client;C:\ProgramData\Oracle\Java\javapath_target_97717435;C:\Program
                               Files (x86)\CodeSynthesis XSD 4.0\bin;C:\Program Files
                               (x86)\CodeSynthesis XSD
                               4.0\bin64;C:\Windows\System32;C:\MinGW\include;C:\MinGW\bin;C:\MinGW\msys\1.0\bin;C:\MinGW\lib\gcc\mingw32\3.4.5\include;C:\WinPython-64bit-3.4.3.4\python-3.4.3.amd64;C:\Python34\Scripts;C:\Program
                               Files\R\R-3.2.1\bin;C:\Program Files\MiKTeX
                               2.9\miktex\bin\x64;C:\Program Files (x86)\Windows
                               Kits\10\Windows Performance Toolkit;C:\Program Files
                               (x86)\Microsoft Visual Studio 14.0\Common7\IDE;C:\Program
                               Files (x86)\Microsoft Visual Studio 14.0\VC\bin;C:\Program
                               Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files
                               (x86)\Microsoft
                               SDKs\TypeScript\1.0;C:\local\GnuWin32\bin;C:\Program
                               Files\doxygen\bin;C:\Program Files\Git\cmd;C:\Program Files
                               (x86)\MiKTeX 2.9\miktex\bin;C:\Program
                               Files\Mercurial;C:\Program Files\TortoiseSVN\bin;C:\Program
                               Files\gs\gs9.21\bin;C:\Program Files (x86)\Pandoc;C:\Program
                               Files\Microsoft SQL
                               Server\120\Tools\Binn;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program
                               Files (x86)\GitExtensions;C:\Program Files
                               (x86)\Intel\Intel(R) Management Engine
                               Components\DAL;C:\Program Files\Intel\Intel(R) Management
                               Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R)
                               Management Engine Components\IPT;C:\Program
                               Files\Intel\Intel(R) Management Engine
                               Components\IPT;C:\Users\Gustaf.Rydevik\Documents\R\win-library\4.0\rstan\include\example-models-master\UsersGustaf.RydevikAppDataLocalMicrosoftWindowsApps;C:\Users\Gustaf.Rydevik\Documents\R\win-library\4.0\rstan\include\example-models-master\
                               c:\rtools40\bin;c:\rtools40\perl\bin;C:\rtools40\mingw64\bin

```

I’m now at a loss - any suggestions?

---

<div class="post-metadata">

**Author:** ![GustafRydevik](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/gustafrydevik/32/1328_2.png) [@GustafRydevik](https://discourse.mc-stan.org/u/GustafRydevik)\
**Post date:** [October 7, 2020, 11:43am UTC](https://discourse.mc-stan.org/t/cant-get-a-functioning-install-with-stan-2-21-0-on-windows-10-and-r-v4-0-2-demo-cant-find-rtools-solved/18462/2 "2020-10-07T11:43:01Z")

</div>

Just found this v. similar issue: [Problems getting Stan to run after upgrading to R 4.0.2](https://discourse.mc-stan.org/t/problems-getting-stan-to-run-after-upgrading-to-r-4-0-2/17896/4)

From that thread, I get the following when checking BINPREF, makevars.win, and Renviron:

```
 Sys.getenv("BINPREF")
[1] ""
> readLines("~/.R/Makevars.win")
[1] "CXX14FLAGS += -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2"
> readLines("~/.Renviron")
[1] "PATH=\"${RTOOLS40_HOME}\\usr\\bin;${PATH}\""

```

Finally, as adviced in the thread, I looked and found an old .Rprofile file where the rtools references were, and after removing it (physically deleting it), it worked! Quest success - sorry for adding a new thread here.

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [October 8, 2020, 1:26am UTC](https://discourse.mc-stan.org/t/cant-get-a-functioning-install-with-stan-2-21-0-on-windows-10-and-r-v4-0-2-demo-cant-find-rtools-solved/18462/3 "2020-10-08T01:26:48Z")

</div>

Glad you got it working!

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [October 8, 2020, 7:07pm UTC](https://discourse.mc-stan.org/t/cant-get-a-functioning-install-with-stan-2-21-0-on-windows-10-and-r-v4-0-2-demo-cant-find-rtools-solved/18462/4 "2020-10-08T19:07:45Z")

</div>

> [@GustafRydevik](#):
>
> Finally, as adviced in the thread, I looked and found an old .Rprofile file where the rtools references were, and after removing it (physically deleting it), it worked! Quest success - sorry for adding a new thread here.

No worries, this is our fault. The rstan installation instructions for R 4.x don’t properly account for the settings that were recommended when installing rstan with R 3.x. Glad it’s working for you now!
