Install all packages from the previous version export OLDV=38 NEWV=39 sudo -E port -pNc install "python${NEWV}" $(port -qv installed | egrep -e "^\s*py${OLDV}" | perl -ane 'chomp; $_ = $F[0]; s/py'${OLDV}'/py'${NEWV}'/; print $_, " ";') port select changes port select --summary | perl -lane '$_=$F[1]; $myset=join(" ", @F[0,1]); $myset =~ s/'${OLDV}'/'${NEWV}'/; /'${OLDV}'/ && print $myset;' | while read line; do sudo port select --set $line; done Uninstall the old packages sudo port -pNc uninstall $(port -qv installed | egrep -e "^\s*py${OLDV}" | perl -ane 'chomp; $_ = $F[0]; print $_, " ";') unset OLDV NEWV