Skip to content

Instantly share code, notes, and snippets.

@idleberg
Last active October 16, 2023 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idleberg/e01e203b46b091f6076669bd0550c66e to your computer and use it in GitHub Desktop.
Save idleberg/e01e203b46b091f6076669bd0550c66e to your computer and use it in GitHub Desktop.
Fixing permissions for MacPorts local repositories

Permissions for local MacPorts repositories

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.

Installation

  1. Download and run the MacPorts installer

  2. Unlike specified in the documentation, the installer did not add /opt/local/bin to my PATH environmental 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

Local Development

  1. 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 git@github.com:macports/macports-ports ~/Development/ports
  1. Edit /etc/macports/sources.conf to 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]
  1. To avoid permission errors, we will also edit /opt/local/etc/macports/macports.conf so a macportsuser will 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
  1. As a last step, you need to index your local Portfile repository.
cd ~/Development/ports
portindex

Note: 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment