Skip to content

Instantly share code, notes, and snippets.

@zadr
Last active December 29, 2024 08:20
Show Gist options
  • Save zadr/e9a090fb564451fb5c76db233fabf0d0 to your computer and use it in GitHub Desktop.
Save zadr/e9a090fb564451fb5c76db233fabf0d0 to your computer and use it in GitHub Desktop.
MacPorts install without root privileges
# fetch MacPorts sources
curl -LO https://distfiles.macports.org/MacPorts/MacPorts-2.8.1.tar.gz
# extract them and get into the dir
tar -jxf MacPorts-2.8.1.tar.gz
cd MacPorts-2.8.1
# configure things
## If you want MacPorts to run in a custom prefix, pass in the following arguments: --prefix=/usr/local --with-unsupported-prefix --with-applications-dir=/Applications
## replacing /usr/local with your desired location
./configure --with-no-root-privileges --with-install-user=$USER --with-install-group=staff --silent
# build and install things, using however many performance CPUs are available
# for older versions of macOS, substitute in `machdep.cpu.core_count`
make -s -j `sysctl -n hw.perflevel0.physicalcpu`
make -s -j `sysctl -n hw.perflevel0.physicalcpu` install
# clean up after ourselves
cd ..
rm -rf MacPorts-2.8.1*
# post-install tasks
## Update ports to latest definitions
port selfupdate
## Edit the config to change any other values that you need, such as setting `buildfromsource` to `always`
### if you passed in a custom prefix via `--prefix`, replace /opt/local with your target prefix.
$EDITOR /opt/local/etc/macports/macports.conf
@Hritik14
Copy link

Hritik14 commented Oct 7, 2023

Works like a charm! Thanks!

make -s -j sysctl -n machdep.cpu.core_count

Why try to find out core count by yourself ?

make --help:
 -j [N], --jobs[=N]          Allow N jobs at once; infinite jobs with no arg.

Also, I had to do

sudo make -s -j install

perhaps because install tries to write to PATH writable only by root ?ˇ

@zadr
Copy link
Author

zadr commented Oct 16, 2023

Why try to find out core count by yourself ?

The number of CPUs in my machine may differ from the number of CPUs in your machine

perhaps because install tries to write to PATH writable only by root ?ˇ

in the years since this gist was written, Apple has changed default permissions of various directories. You can make a new directory and install to other locations (/opt, /Users/`whoami`/.usr, etc) as needed.

@Hritik14
Copy link

Hritik14 commented Oct 16, 2023

The number of CPUs in my machine may differ from the number of CPUs in your machine

Allow N jobs at once; **infinite jobs** with no arg.

Isn't infinite jobs = no of cores at a time? Shouldn't need to specify the core

@zadr
Copy link
Author

zadr commented Oct 17, 2023

Isn't infinite jobs = no of cores at a time? Shouldn't need to specify the core

What are you hoping to get out of this thread? The gist we're talking on is a set of notes I wrote down for myself, and specifying the number of cores gives me the behavior I'm looking for.

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