openbsd ports and packages
I mainly use packages to install 3rd party software, but sometimes you need ports to install software that has distribution or licensing limitations as well as a way to customize packages when the default flavor doesn't suit your needs. Ports can also be an easy way to browse for software you will install via packages.
PACKAGES
Run the following commands to beable to install packages without having to specify the full path everytime. Use your local mirror. Note: I'm using a snapshot (4.5-BETA as of this writing). If you aren't running a snapshot change snapshots in the path to whatever version of OpenBSD you are using. It is important to use packages that match your version of OpenBSD. Keep it all in sync yo!
# PKG_PATH=ftp://rt.fm/pub/OpenBSD/snapshots/package/i386/
# export PKG_PATH
Now just add packages with sudo pkg_add <pkg_name>. That easy. That is only gonna work for this login. add those same lines to your ~/.profile to have them stick for every login.
It is recommended that you use packages instead of ports when available. Unless you need ports for a specific reason just use the package. This isn't Gentoo. Compiling your packages with crazy flags isn't going to squeeze more ummmmffff out of them. If that's what you think you want, you may want to look elsewhere.
PORTS
Like I said before, use packages when you can. But ports do come in very handy. First just download a ports tarball from your mirror. NOTE: Same as with packages, I'm using a snapshots tarball of ports. Get the tarball that matches your version of OpenBSD. Its important!
# ftp ftp://rt.fm/pub/OpenBSD/snapshots/ports.tar.gz
Now that we have it. We need to decompress it, change the group ownership of it to the wsrc and then change the permissions on the ports tree to allow us (a membe rof the wsrc group) to build packages in it. This way we dont have to sudo or su just to build software.
# sudo tar vxfz ports.tar.gz -C /usr/
# sudo chgrp -R wsrc /usr/ports
# sudo find /usr/ports -type d -exec chmod g+w {} \;
Now we can build software as a normal user. But obviosuly we can't install the software to other parts of our system. To fix this we can edit /etc/mk.conf and add the following. Now when installing ports as our regular user it will run sudo when it needs root privileges
SUDO=/usr/bin/sudo
Now you can run make and make install as a normal user without having to sudo before it every time. When the ports system wants to install the files it will run sudo for you and prompt for a password.