Getting local Portfile repository for MacPorts running is difficult, if not annoying. The documentation doesn't provide much help or, worse, is even outdated. Hopefully, the following steps will help avoiding the problem I had.
-
Download and run the MacPorts installer
-
Unlike specified in the documentation, the installer did not add
/opt/local/binto myPATHenvironmental variable. However, since I don't use the default macOS shell, the problem might actually be on my end.
# Bash or Zsh
export PATH=/opt/local/bin:$PATH
# Fish
set -Ux PATH /opt/local/bin $PATH- To edit or add new Portfiles, you likely want to clone macports/macports-ports first. Througout this chapter, I will refer to my local Portfile repository as
~/Development/ports.
git clone [email protected]:macports/macports-ports ~/Development/ports- Edit
/etc/macports/sources.confto add your local Portfile repository path. Make sure you add it _before the rsync URL.
Example
file:///Users/<YOUR_USERNAME>/Development/ports
rsync://rsync.macports.org/macports/release/tarballs/ports.tar [default]
- To avoid permission errors, we will also edit
/opt/local/etc/macports/macports.confso amacportsuserwill be set. The relevant line is commented by default. The following works for me, but then again I don't really know what I'm doing.
# User to run operations as when MacPorts drops privileges.
macportsuser root- As a last step, you need to index your local Portfile repository.
cd ~/Development/ports
portindexNote: If you haven't cloned macports/macports-ports and work with your own files, make sure to place your Portfile into the correct folder structure. MacPorts expects your Portfile to be in any of the predefined categories (e.g. devel/nodejs18/Portfile).
That's it. You should now be able to add or edit Portfiles and have the correct permissions to run sudo port test or sudo port -vst install.
Please let me know in the comments, if you have any suggestions on how to improve this guide!