Adding Nodejs to MacOS
Every time I set up a new Mac, I follow a specific process to install my command-line programming tools. My goal is simple: create a development environment that closely mirrors the RHEL web servers I work with daily. This guide outlines that process.
My philosophy is to keep things as simple and transparent as possible. I often find that modern package and version managers, while powerful, add layers of complexity I don’t need. I rarely require multiple versions of a programming language on the same machine, and I don’t want to guess where my binaries and libraries are located. Instead, I prefer a stable, predictable architecture where I know exactly where to find everything.
If you share that “get off my lawn” approach to development environments, this guide is for you.
Nodejs
It seems like there are a dozen different ways of installing nodejs
, but I avoid them all. For me, this manual method is the One True Way. It works on linux and macos, and it is trivial to upgrade.
Download the prebuilt binaries from https://nodejs.org/en/download/prebuilt-binaries for your system. Copy the files into /usr/local/
. Done!
Here’s how it looks in the terminal. Remember to replace the version number with the latest one you downloaded!
# Navigate to your Downloads folder
$ cd ~/Downloads
# Unpack the archive (your filename will vary)
$ tar xvf node-v20.16.0-darwin-x64.tar
$ cd node-v20.16.0-darwin-x64/
# Copy the directories into /usr/local
$ sudo cp -a bin /usr/local
$ sudo cp -a include /usr/local
$ sudo cp -a lib /usr/local
$ sudo cp -a share /usr/local
# Verify the installation
$ node --version
v20.16.0
To install global NPM packages, I use the -E flag with sudo to preserve the user environment, which can help prevent certain permission errors.
# Example: installing node-sass globally
$ sudo -E npm install -g --unsafe-perm node-sass
Perl
I’m now (finally!) ready to install Perl and the modules that I use every day.
In my notes from previous installations, I made a big sign for myself:
****************************************************************************
** Do *not* use the system Perl on MacOS. That is for Apple, not for you. **
****************************************************************************
Installing perl from brew is a jungle nightmare of random symbolic links and hard-coded version numbers. I don’t understand it at all. It makes it extremely difficult to upgrade the version, and I think all the compartmentalization is unnecessary for a language that prides itself on backward compatibility.
Instead, I prefer to install it to /usr/local/, without version numbers, with any modules downloaded directly in a separate location. You know, like we did it in the aughts.
$ brew install wget $ cd ~/Downloads $ wget https://www.cpan.org/src/5.0/perl-5.40.0.tar.gz $ tar xvzf perl-5.40.0.tar.gz $ cd perl-5.40.0/ $ Configure -des -Dprefix=/usr/local -Dsitelib=‘/usr/local/lib/site_perl’ -Dsitelib_stem=‘/usr/local/lib/site_perl’ -Dsitelibexp=‘/usr/local/lib/perl5/site_perl’ -Dsitearch=‘/usr/local/lib/site_perl/darwin-2level’ -Dsitearchexp=‘/usr/local/lib/site_perl/darwin-2level’ -Dinstallsitearch=‘/usr/local/lib/site_perl/darwin-2level’ -Darchlib=‘/usr/local/lib/perl5/’ -Dprivlib=‘/usr/local/lib/perl5/’ $ make $ make test $ sudo make install
Of course we’ll also need cpanm
and I use ack
instead of grep
.
$ curl -L http://cpanmin.us | perl - --sudo App::cpanminus $ cpanm --sudo App::Ack
Commonly Used Perl Modules
$ cpanm --sudo CGI $ cpanm --sudo Path::Tiny $ cpanm --sudo Data::Printer $ cpanm --sudo Mojolicious
Readline
$ brew install readline
Perl Debugger
$ cpanm --sudo DB::Pluggable $ cpanm --sudo Term::ReadLine::Gnu
Playwright.pm
Playwright.pm requires playwright
to first be installed manually.
$ sudo -E npm install -g uuid express playwright $ npx playwright install
It uses Test2::Harness which I’ve had some issues installing in the past, so let’s install it ahead of time.
$ cpanm --sudo Test2::Harness $ cpanm --sudo Sereal::Encoder $ cpanm --sudo Playwright