Knowing how to install a package manager on macOS gives you the ability to install software packages directly from the Terminal command line. Because some package managers cause security issues, I advise to use MacPorts. The reason is that the MacPorts installer doesn’t change any folder permissions and thus keeps your system secure.
You can download MacPorts here. Don’t forget to verify the software integrity of the downloaded pkg installer.
Installation is very straightforward and takes only eight easy steps to complete after double-clicking the pkg installer. If you keep the default settings, that is.
Fig. 1: Click “Continue”

Fig. 2: Read and click “Continue”

Fig. 3: Click “Continue” if you agree to the software licence agreement

Fig. 4: Click “Agree” if you agree to the software licence agreement

Fig. 5: Click “Install” if you accept the default install location /opt/local/bin (advised)

Fig. 6: Enter your administrator credentials and click “Install Software”

Fig. 7: Click “Close”

Fig. 8: You can either “Keep” or “Move to Bin”

Congratulations, you now know how to install a package manager on macOS. The MacPorts program can be found in the /opt/local/bin folder in the Terminal.
Don’t stop here though and try installing software packages on your Mac directly from the Terminal command line, using MacPorts commands. Git is a good package to start with if you’re interested in becoming a programmer.