Rstudio can't find CMAKE even though it is in /usr/local/bin

nloptr can be quite picky when it comes to cmake - Which version of cmake do you have in /usr/local/bin (cmake --version) ? On my Mac I have cmake 3.23.3 and this works quite well allowing be to build nloptr 2.0.3 successfully from sources.

"Only" reason for nloptr to actually need cmake is if it cannot find any installation of nlopt on your system - in such a case nloptr needs to not only build the R package but also build the nloptsoftware that nloptr provides an interface for.

Another avenue that you could take in order to solve your issue is to use R package binaries.

install.packages("nloptr",repos="https://cran.rstudio.com/",type="binary" )

should automatically install R package binaries and hence circumventing the cmake issue to start with.

(Cross-linking an earlier issue about nloptr for awareness Installing package nloptr)