Howtos FreeBSD Basic Software Management Using Ports
From 5dollarwhitebox.org Media Wiki
Contents |
Summary
I am by far not a FreeBSD guy. However, I figure since I'm learning this stuff why not make some basic docs on how to do some stuff for the other johnnies like me. This here will serve as your basic introduction to the Ports Tree, updating packages, installing software, etc.
- Author: BJ Dierkes
- Last Update: January 23, 2006
- Contact: wdierkes [at] 5dollarwhitebox [dot] org
Preparation
I am not starting from scratch here, but what I do have is a base install of FreeBSD 5.4-RELEASE with nothing else installed really. When installing I selected to "Install the Developer/Ports Collection" or however it presented itself. If you have not done so, you can use '/stand/sysinstall' to grab this which I will show you here. The following are necessary:
- FreeBSD Base Installation
- Internet connectivity (Can you ping out?)
Install Ports
Generally this is done from '/stand/sysinstall' however on another system you may need to locate 'sysinstall':
root@freebsd-box# which sysinstall /usr/sbin/sysinstall
Run this application, and follow my points:
root@freebsd-box# /stand/sysinstall + Select "Upgrade => Upgrade an existing system" + Hit Enter twice after reading the messages + Select "4 Developer => Full sources, binaries and doc but no games" + Select "Yes" to use the "Ports Collection" + The rest is self exclamatory and you can following the installer to perform the upgrade
Install CVSUP
You will need to install 'cvsup'. Again this can be done through '/stand/sysinstall':
root@freebsd-box# /stand/sysinstall + Select "Configure => Do post-install configuration of FreeBSD" + Select "Packages => Install pre-packaged software for FreeBSD" + Choose "FTP" or "FTP Passive" if you are behind a firewall + Select an FTP Server + Select "devel => Software development utilities and libraries." + Select "cvsup-without-gui-16.1h_2" or whatever you see on your screen for "cvsup-without-gui..." + Select "OK" and following the prompts to install your selections
Configure CVSUP
Ok, now that cvsup is installed we can get it config'd. If you are using CSH you may need to run the command 'rehash' inorder to re-read your $PATH and see this new binary. Follow me as we config cvsup:
COPY AN EXAMPLE: root@freebsd-box# cp /usr/share/examples/cvsup/stable-supfile /usr/ports/ports-supfile EDIT THE FILE: root@freebsd-box# vi /usr/ports/ports-supfile CHANGE THE LINE: *default host=CHANGE-THIS.FreeBSD.org TO SOMETHING LIKE: *default host=cvsup13.FreeBSD.org
And there you have it, your very own 'ports-supfile'...
Updating the Ports Tree
Before installing anything from Ports, you always want to make sure that you have the latest packages. To do this we do 'cvsup' using our ports-supfile:
root@freebsd-box# cd /usr/ports root@freebsd-box# cvsup /usr/ports/ports-supfile Connected to cvsup13.FreeBSD.org Updating collection src-all/cvs .... Finished successfully
This will run for quite some time so please take a moment to reflect on what we have accomplished... [insert dramatic pause]
Installing Software From Ports
Ok ok ok... this is easy isn't it? Well, it can get complicated... but since I don't even know that stuff in BSD yet we're going to keep things simple. If it has been a day or two since installing software you will want to run the previous command to update the Ports Tree doing 'cvsup'.
Generally, you will begin to see the file layout of software that is installed via Ports:
- Config files: /usr/local/etc
- Binaries: /usr/local/bin
- Start Scripts: /usr/local/etc/rc.d
If you want some information on the package you are installing, try less'ing the Makefile in the packages directory. Apache for this example starts off with some good information such as Major/Minor revision, Maintainer, Dependecies, etc:
root@freebsd-box# less /usr/ports/www/apache21/Makefile
...
PORTNAME= apache
PORTVERSION= 2.1.4
CATEGORIES= www
MASTER_SITES= ${MASTER_SITE_LOCAL:S/%SUBDIR%/clement/}
DISTNAME= httpd-${PORTVERSION}-alpha
DISTFILES= ${DISTNAME}.tar.bz2 powerlogo.gif
DIST_SUBDIR= apache21
EXTRACT_ONLY= ${DISTNAME}.tar.bz2
MAINTAINER?= clement@FreeBSD.org
COMMENT?= Version 2.1 of Apache web server with ${WITH_MPM:L} MPM.
LIB_DEPENDS= expat.5:${PORTSDIR}/textproc/expat2
BUILD_DEPENDS= python:${PORTSDIR}/lang/python
...
Example 1: Installing Bash
Now, since I absolutely hate CSH the first example we are going to use is installing BASH:
root@freebsd-box# cd /usr/ports/shells/bash root@freebsd-box# make install clean
This is going to take a little time depending on your machine, but you see what we are doing is:
- Compiling the sources
- Installing the binaries, config files, libraries, etc
- Cleaning up after ourselves
Once done, the software is installed. You can go ahead and run the software "/usr/local/bin/bash" and now you can use a not-so-annoying shell. Be sure to change your users default shell using the 'chpass' command as well... and never use CSH again. ;)
Example 2: Installing Apache2.1.4
Here you can see how to make apache2 and configure it to run on startup:
root@freebsd-box# cd /usr/ports/www/apache21 root@freebsd-box# make install clean
Again, simple as that. Now of course at some point you will actually want/need to edit the sources/Makefile/config in some way to suit your needs. But not here we aren't! Now that Apache2 is installed wouldn't we like for it to start? The start scripts themselves generally give you the information you need to get the application configured for startup:
root@freebsd-box# head -n30 /usr/local/etc/rc.d/apache21.sh ... # # Add the following lines to /etc/rc.conf to enable apache21: # apache21_enable (bool): Set to "NO" by default. # Set it to "YES" to enable apache21 # apache21ssl_enable (bool): Set to "NO" by default. # Set it to "YES" to start apache with SSL # (if <IfDefined SSL> exists in httpd.conf) # apache21limits_enable (bool):Set to "NO" by default. # Set it to yes to run `limits $limits_args` # just before apache starts. # apache21_flags (str): Set to "" by default. # Extra flags passed to start command. # apache21limits_args (str): Default to "-e -C daemon" # Arguments of pre-start limits run. # ...
We see from this output that all we need to do is add "apache21_enable=YES" to '/etc/rc.conf' in order for this daemon to start on boot up. So lets do that:
root@freebsd-box# vi /etc/rc.conf ADD THE LINE: apache21_enable=YES
Now we can start up the service, but before doing that lets see what we *can* do with the start script. Run without options spits out its capabilities:
root@freebsd-box# /usr/local/etc/rc.d/apache21.sh Usage: /usr/local/etc/rc.d/apache21.sh [fast|force|one](start stop restart rcvar reload status poll)
START THE SERVICE:
root@freebsd-box# /usr/local/etc/rc.d/apache21.sh start Starting apache21.
Example 3: Installing MySQL4.1.10a
So, just to show you again the consistent ease of this stuff we are going to install MySQL4.1.10a:
root@freebsd-box# /usr/local/etc/rc.d/apache21.sh root@freebsd-box# make install clean
This will also include mysql-client for you. Wait forever and then you'll have MySQL-server and MySQL-client.
Configure it to start:
FIND THE RIGHT ENTRY: root@freebsd-box# head -n30 /usr/local/etc/rc.d/mysql-server.sh ... # # Add the following line to /etc/rc.conf to enable mysql: # mysql_enable (bool): Set to "NO" by default. # Set it to "YES" to enable MySQL. # mysql_limits (bool): Set to "NO" by default. # Set it to yes to run `limits -e -U mysql` # just before mysql starts. # mysql_dbdir (str): Default to "/var/db/mysql" # Base database directory. # ... ADD THE ENTRY TO THE STARTUP SCRIPTS: root@freebsd-box# vi /etc/rc.conf ADD THE LINE: mysql_enable=YES
Then start her up:
root@freebsd-box# /usr/local/etc/rc.d/mysql-server.sh start Starting mysql.
Managing Software Upgrades with PortUpgrade
Ok, so now you have software installed. And two days later a security patch is released for something you have installed. The way to manage package upgrades is with 'portupgrade' which needs to first be installed from ports:
root@freebsd-box# cd /usr/ports/sysutils/portupgrade root@freebsd-box# make install clean
Now that 'portupgrade' is installed, we can do the dance... but first do your CVSUP updates:
root@freebsd-box# cd /usr/ports root@freebsd-box# cvsup /usr/ports/ports-supfile root@freebsd-box# portupgrade -ai
There are a bit of options you can use, just check out 'portupgrade --help'. Here I am just doing "-a [all]" and "-i [interactive]". And there you have it, you've just upgraded your system based on available updates through the Ports Tree.
Conclusion
And there you have a *very* simplistic and basic introduction to getting things squared away in FreeBSD using Ports. Please let me know if I can add anything to this.
Resources
- FreeBSD Unix: http://www.freebsd.org
- FreeBSD Ports: http://www.freebsd.org/ports
- FreeBSD Handbook: http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/
