Introduction
If you have ever been interested in developing applications for Unix/Linux, but didn't know where to start in terms of getting your environment set up, then this article is for you. To that ends, the intent of this article is to describe how to do so by using a popular flavor of Unix-like operating systems, called FreeBSD, and at the same time familiarize you with some of the basics.
Conventions
This article will take advantage of the usage of screenshots - where applicable - to assist in the explanation of certain steps. In an effort to avoid having a mile long article, any screenshots will be denoted by an icon and can be viewed in a popup window by clicking it. Should you prefer to have inline screenshots, please make use of the accompanying PDF file for this article.
Obtaining FreeBSD
The intent of this article is to provide you with a clear-cut path that starts with nothing to having a fully graphical development environment similar to Windows and with a powerful IDE for developing applications on for Unix/Linux. By the time we're through you should have something akin to the screenshots featured above this paragraph.
FreeBSD is considered free software and licensed under the BSD License. As such, it costs nothing to obtain, use, and modify as you see fit, for whatever purpose commercial or otherwise. At the time of this writing, the latest version of FreeBSD is 6.1. This is the version the article assumes the reader will be using.
You can obtain it either by downloading the source, downloading a CD image, or purchasing the CD via a retailer. The benefit of the last option is that profits from the purchase help fund the project, but it is not required. For the sake of this article, we will assume you have downloaded the CD image and burned it to CD or purchased the CD.
To download, visit www.freebsd.org/where.html[^]. In all likelihood you'll want the i386 ISO download if you are running a 32-bit x86 processor. If you happen to be running a 64-bit AMD or Intel processor you'll want amd64 or ia64 respectively. For your convenience, if you are running a 32-bit x86 processor here is a direct link to download the CD image for disc 1 (505 MB) for version 6.1.
To get everything up and running we will only need disc 1, as we will download the rest of the software we need for the latest versions.
Installing FreeBSD
Note: Please be aware that if you plan to dual boot two operating systems, the installation for FreeBSD has the ability to wipe out the entire hard disk. Therefore, do not jump ahead, and this material is presented to you for use at your own risk. I assume no liability for those people who have to sue everyone. If you are concerned about data loss either perform a back up or consider using a different machine or virtual machine.
Note: It is important that you know that unlike in Microsoft Windows, everything in the Unix/Linux world is case sensitive, and I mean everything.
Note: You'll want to reserve at least 5GB for the hard drive and/or partition (of course the more the merrier) for the installation of FreeBSD and the graphical environment and development tools. FreeBSD can be installed with a lot less room, but we will accept a lof of defaults during the installation to smooth out the flow of this article.
The CD is bootable, so place disc 1 in the drive and crank up the computer. What you'll notice is a series of batons to indicate the loading of a temporary kernel, etc., followed by a simple boot screen. If you so desire, please use the icon above this paragraph if you would like to confirm what the boot screen looks like. If you have a USB keyboard choose seven; otherwise, wait for the default to be chosen or select option number one.
After the selection you should notice plenty of text scrolling by saying various things. If it looks like The Matrix, don't worry. It's just loading a temporary mini-OS to run the installation with. Unix-like and Linux operating systems have a tendency to show practically everything that's going on during the bootstrap. Once FreeBSD is installed this can be changed (as we'll discuss) to keep the environment more graphical. For now, just enjoy the show.
You should arrive at the first screen for the installation program. Simply use the arrows keys to select your country and hit enter.
Now we are at the main menu for the installation program. Once again, we can use the arrows keys to select the "Standard" installation and hit enter. A message box should appear letting you know the next step is to set up DOS-style partitions. Just hit enter to pass this as it will be explained on the following screen.
You will only see this screen if and only if you have two or more hard drives on the computer or virtual machine FreeBSD is being installed on. At this point it is very important to understand how FreeBSD and other Unix-like operating systems name the drives on the system. The drives are named by the driver that's used to work with them with a number appended on the end.
For instance, in the screenshot above, the system in question has three IDE drives. The driver FreeBSD uses for IDE is called ad for ATAPI Disk. They are numbered according to the order that the BIOS will list them in. By default the order would be controller 0,0 = drive 0; controller 0,1 = drive 1; controller 1,0 = drive 2; and controller 1,1 = drive 3.
If you are using SCSI or SATA drives. The driver FreeBSD uses is called da. The number used in the drive name is based on the controllers as well and the order in the chain. Also, if you intend to set up a RAID the naming is a bit different, and falls out of the scope of this article. However, if you need to opt for this a quick Google should provide you with information on naming conventions used.
Select the drive with spacebar to enter the next screen.
Note: If you do not know which drive belongs to which controller it would behoove to you restart and enter the BIOS setup to get this information before proceeding. After all, you don't want to wipe out the wrong drive. Also, POST should show you the ordering.
FDISK (No Slices)
FDISK (Existing Slices)
FDISK (FreeBSD Slice)
This is FDISK and its purpose is very similar to that of Microsoft's version. First and foremost, what you think of as a partition, FreeBSD refers to as a slice. The reason for this will become more apparent in a couple of screens, but suffice it to say will we create partitions later on in the slice we setup on this screen. So in essence a partition in FreeBSD is really like a partition in a partition from a Windows standpoint. There are technical benefits to this architecture, but it falls out of the scope of this article. For now, just be aware of the terminology used.
It can be a bit involved if you are new to the Unix world. The good news is if the machine only has one hard drive and you plan on using the entire disk, your life has been made real simple. Just type in the letter A on the keyboard and you are set. Otherwise you should use the arrow keys to select unused space and then press C to create a slice. On the prompts that follow, just hit enter to accept the default values. They serve our purpose just fine as they will assume the maximum size possible and use a native FreeBSD slice.
When you are finished, you should have something similar to the screenshot labeled FDISK (FreeBSD Slice). Do not worry about any extra unused space before your slice. It is always reserved for the MBR and related bootstrap applications. Also, depending on the slice type, you may also have unused space at the end due to certain size restrictions. It should be minimal if it does appear and it is not a problem. This is not an issue exclusive to FreeBSD, but rather partitions/slices in general.
Once you have created a FreeBSD slice, hit Q on the keyboard to move on the next screen.
This screen is fairly straightforward. If you intend on dual booting operating systems you'll need what's referred to as a boot manager. FreeBSD will provide you with one or you can use a third party manager by leaving the MBR untouched. If this computer or virtual machine will be dedicated to FreeBSD, the second choice is the way to go. In choosing it, FreeBSD will start automatically when powering on the system. Select your choice with the arrow keys and hit enter when done. At this point you will be provided information regarding the upcoming screen. Simply use enter to pass it.
This is where we create those partitions in a partition mentioned earlier. Since our goal is to create a development environment and not a high performance server hosting thousands of users, we can simply strike A on the keyboard and accept the defaults. Once the defaults have been entered, press Q and we are finished with this screen. If there is more than one hard drive on the machine, you will then be returned to the select drive screen. You can simply tab out and select ok to continue.
Here the FreeBSD installation is making things a bit simpler by giving us the option of selected commonly used installation types. That is to say it will automatically install the software and tools (including source code) that will be required to have installed anyway if we want to perform certain tasks, like developing in a graphical environment.
For this step use the arrow keys to choose X-Developer and hit spacebar to move on to the next screen.
The ports collection consists of software made for Unix and/or Linux that has been ported to FreeBSD already for us. The beauty of this system is it automatically takes care of dependencies to make installing software extremely simple. The downside to this is there are over 14,000 ports available and choosing yes here will install a skeleton directory structure. I personally do not like a bloated system and prefer only installing software that I intend to use.
This is by far the best way to go if you wish to modify any of the software's source code, but in our case we just want to install it. Conveniently, FreeBSD also offers a packaging system that is built on top of the ports system, the difference being the software is precompiled for us and can be used on a one-by-one basis. We will be taking advantage of this to make installing the graphical environment much easier.
We can choose No to move on to the next screen.
This screen asks for a few selections regarding the X server (more on that later) we selected to install. Fortunately, the default selections are just fine for what we want to accomplish. Simply choose Exit to return back to the distribution screen that we just came from.
Once back on the distribution screen we can now tab and select Ok and press enter to proceed.
This screen may seem out of place at first, but the reason it ask this question is because the installation program we have been using does not have to be run from the CD we have. You could have chosen to use diskettes for this software to download the entire OS, perform a network install, etc. It was provided with the CD image just to make the install easier. Needless to say, we want to choose to install from a CD/DVD and move on to the next screen.
At this point you will be warned that you are about to pass the point of no return. Go ahead and select Yes and watch the fun begin. When this is done with you will receive a congratulations message telling you that you have now installed FreeBSD, and it's time to configure it a bit.
Configuring FreeBSD
You will be asked if you wish to cofingure any Ethernet or SLIP/PPP devices - choose Yes to proceed to the screen shown in the screenshot.
If you have a modem, you will want to choose PPP on the com port the modem is attached to. Please note that you will also need a dialer (several are supported) and a hardware-based modem. If you have a software-based modem, some are supported but first you will need to download, compile, and install the software and then configure the modem.
This article assumes that either we are connected via broadband or over a network to another machine. As such, we want to setup an Ethernet adapter. If you are using a fairly standard adapter, FreeBSD should recognize it automatically and list it as the first option - as shown in the screenshot.
If you do not see it, it may not be supported. Refer to this page[^] to make certain (for FreeBSD 6.1 on i386). Otherwise, select it and hit enter. It will ask if you wish to use IPv6, to which we will answer No. It will then ask for DHCP configuration and we want to answer Yes.
If you have broadband, you are most likely using DHCP for automatic configuration already. If this is the case, you should have all the needed information filled in already - as shown in the screenshot. Although, the local IPs were changed in the picture for security reasons. Just tab on down to Ok and press it to get to the next screen.
If this is blank, then FreeBSD cannot contact your or your ISP's DHCP server. If you are not using DHCP, then simply fill out the required data for your network. Proceed to the next screen.
At this point the installation will ask another series of questions. Feel free to choose whichever answers you want, but to keep things simple I will simply supply a general set of answers that will serve the purpose of creating a development environment.
| Do you want this machine to act as a network gateway? | No |
| Do you wish to configure inetd? | No |
| Do you wish to enable SSH logins? | Yes |
| Do you wish to allow anonymous FTP? | No |
| Do you want this machine to act as a NFS server? | No |
| Do you want this machine to act as a NFS client? | No |
| Do you wish to customize console settings? | No |
| Do you wish to adjust this machine's time zone? | Yes |
You will then be asked if your machine is set to UTC or local time. Most machines are set to local time, so for this we will choose No and then be brought to the screen shown in the screenshot.
This is straightforward, select a region, then your country and finally select your time zone. Afterwards, it will ask you if the abbreviation for your time zone looks reasonable. It usually is, so just choose Yes. Once again, we have another series of questions to endure. Like the last time I'll choose answers related to our goal at hand.
| Do you wish to enable Linux binary compatibility? | No |
| Does the system have a PS/2, serial, or bus mouse? | Yes |
You should now be at the screen shown in the screenshot. If you have a fairly standard mouse you more than likely won't have to specify anything. You can just select Test and run the mouse daemon (think of a daemon as a service in the Windows world).
Move the mouse around a bit to see if it is working. If it's not, answer No to the question that ask if it's working and then select a new port and protocol and test the mouse again. Once you have a working mouse, answer Yes to the question to go back and then exit the menu.
You will then be asked if you would like to browse the packages collection. Remember when we talked about ported software earlier and that packages are precompiled software from the ports collection? Well, this is it, but choose No to browse becuase we'll download the latest versions from the Internet instead.
You are now asked if you would like to add any additional user accounts and by all means it is strongly recommended that you do so. So, answer Yes to the question to be brought to the screen in the screenshot.
Just like in Active Directory for Windows, users belong to groups in Unix/Linux. The idea is to ease administration. As such, before we create new users for the system we need to first create a group they will belong to. So, select Add a new user group to the system.
You will then be brought to this screen. For Group name I just choose "users" as that's common nomenclature for the Unix/Linux world. Enter the name you want and leave the rest of the fields at they are. After selecting ok, you'll return back to the previous window. This time select Add a new user to the system.
Now it's time to create the actual user account. Your login id can be whatever you want. Just remember it'll be case sensitive. The UID (user id) can be left alone. For Group make sure you specify the one we just created. In this example it is "users". The password should be self-explanatory. Full name is optional.
Member groups should be set to wheel. Think of this as a second group the user can belong to. It's not required to fill in, but I recommend it be set to wheel for your account and your account only. If you ever want to su (super user) - that is gaining the permissions of administrator - using this account it most belong to wheel.
I left the default for the home directory and changed my shell to /bin/tcsh as I prefer the c-style syntax. If you are used to the Linux way of life you may prefer to use bash instead, although it will need to be installed first. When finished, your screen should look similar to the screenshot. After selecting Ok you will be taken back to the user and group management screen again. Simply choose Exit this time. You will be notified that you should set the system manager's (a.k.a.; root) password at this point. Select Ok to continue.
At this point, just type in the password you want to use. It will not echo any characters to the screen at all. Just type it in, hit enter, and retype it to confirm the password and press enter again.
As a security precaution it is recommend that this not be the same password as your normal user account. Should anyone get a hold of this password they can trash the entire system.
You will be asked to revisit the configuration editor in case you have any last minute changes. Simply select No to go back to the main menu and tab out to select Exit Install. It will ask you to confirm your decision to exit. Only after you hit Yes can you remove the CD from the drive as the program locks it. Do make sure however that you remove the CD before the system restarts so we don't enter setup again. Finally, congratulate yourself for getting through the installation and configuration of the FreeBSD operating system.
When FreeBSD restarts you'll see the same boot screen you saw earlier. In fact, choose the same selection - either 1 or 7 depending on your needs.
Note: Usually after installation a system administrator will recompile a new kernel to speed up the system, make it a bit more stable by not loading drivers, etc. that the system does not need, and even add new functionality. However, for our purpose we will skip this as the generic kernel will do just fine for our development needs.
Since we elected to install ssh during the installation, there will now be a one-time warning message displayed during startup. It will speak of setting an entropy source, that is to say a series of random characters/junk from the keyboard, to use as the seed for encryption to be used with ssh. Without going into the details, it is much more secure than not salting the seed and/or using a system based time as the salt (as most do). Simply type in a random sentence or garbage and press enter. You can change this later if you wish, but after the first time you will not be prompted again.
X Window System
Note: The remaining software installations for this article assume that you have a valid Internet connection (we used DHCP during the install) as the commands used will automatically retrieve the latest versions of the software online.
You may have heard of this before (or incorrectly called "X Windows"). Without getting into too much detail the idea of a windowing environment (ala GUI) in Unix/Linux, know that it runs in a client/server model. The server side of it interfaces with the hardware (mouse, keyboard, monitor, etc.) and the client side of it is the software that interacts with the server. As such we need both server and client software to get our windowing system and graphical development environment up and running.
By far the most popular server is X (a.k.a.; X11). There is a free implementation of it called Xorg (for you old-timers, it was based on XFree86 4.4RC2). This was already installed during setup, but now we need to configure it. To begin login as root (the super admin, username is "root" and all lowercase) using the password you specified during the installation, and type the following command at the prompt:
xorgconfig
This will be a series of yes/no and multiple choice questions to set this up. They do not need much explaining, but I will provide a brief description of the important steps along with a screenshot.
Ok, the good news is X is now configured. We can make minor tweaks later, but first let's get that graphical environment up and running.
KDE
Remember the client/server model we spoke for X? Well, to get the GUI we want, we need to install what's referred to as a window manager that runs as a client on top of X. For those familiar with Microsoft Windows, think of Windows 98. X would be analogous to DOS (handled the hardware interfacing, etc.) and a window manager would be like Windows that sat on top of DOS.
Some window managers are simple and some are complex. For this article, we will be using the K Desktop Environment (KDE). To install the latest version from the Internet you must be logged as root and specify the following command:
pkg_add -r kde
This step is the equivalent of installing Microsoft Windows, Microsoft Office, and Microsoft Visual Studio Professional over the Internet all into a one-stop shop. So, expect this to take a bit. But since it's all automated feel free to sit back and relax. If you start seeing messages saying failure and speaking of the file system, then you've probably ran out of disk space. You'll need to reinstall with a larger slice (partition) that is at least 5GB. Also if the screen goes blank, that's just the default screensaver for the console. Move your mouse to make it go away without interrupting the install.
When finished you'll be at a prompt again. You should logout as root at this point. Logging in as root should only be done when making system wide changes before you go into X - other than that just don't do it. In fact this will probably be the last time you ever log in as root directly again. To logout use the following command:
exit
Remember the additional user account we created during the installation? It's time to login to that account using whatever username and password you specified. It's the same exact process as before, just using a new name. Once in, the prompt will now appear different. This indicates you are no longer an administrator.
If you are new editing text in the Unix/Linux world then ee is your new best friend for console-based text editing. Its schematics are much more like working with Notepad than many of the other editors available. It's not as powerful as other editors, but it will do just fine to get things up and running. And now is the perfect time to use it because we need to alter a configuration file manually. Use the following command to get things going:
ee .xinitrc
You should be presented with a screen like the one shown by the first screenshot. Take note that the text at the top is a reference of control characters to perform various tasks. All that needs to be done is to simply type in exec startkde in all lowercase. Then press ESC on the keyboard to be shown a menu as depicted in the second screenshot. Use the arrows keys to select leave editor and enter. You will be asked to save the file. Select the save file option and press enter again. Next is the magic moment we've all been waiting for. Type in the following command at the prompt:
startx
This will start the X server and KDE. You will be presented with the following wizard the first time you start KDE.
By now you should have an up and running installation going. If you receive an error message about a sound driver there's a very good reason; we didn't set it up. Since this falls out of the scope of the article you can elect to not show the message again. You now have access to programs such as games, office applications, development IDE, web browser, and many utilities. It's important to take some time to play around bit to learn your way around.
Note: You can click on the K Menu (basically the Start Menu equivalent) and go to Control Center to configure the way KDE operates.
KDM - Login Manager
If you would like to boot directly into a graphical environment from here on out (recommended if you're new to Unix/Linux) there is a program called the KDE Display Manager (KDM) that will allow just that. It's quick to configure and once that's done you'll always end up with a GUI when the computer starts.
To configure it, go to the K Menu » Control Center » System Administration » Login Manager. Refer to the screenshot to ensure you're in the correct spot. There's a Administrator Mode button at the bottom. Click it and you'll be prompted for the root password. Once through, everything is now enabled.
I'm only going to cover the important settings for security's sake. Everything else is up to your preference. Click on the Users tab at the top-right. In the left of this pane is a series of options called Users. As a security precaution remove the check that says "Show list". Just to make sure there is no misunderstandings, please refer to the screenshot.
Once this setting and whatever other preferences you have are satisfied, click OK to save it and close out everything. There's one more step to finalize this, so go ahead and log out of KDE (K Menu » Log Out). You should now be back at the command prompt.
To edit the file we need to we'll need administrator privileges, but we don't ever want to log in as root again. To solve this, type in the following command:
su root
The su stands for super user, basically the administrator. What we are accomplishing here is elevating our privileges for the normal user account. Of course, you have to provide the password for root and hit enter. Notice, once again you have a new prompt to indicate you are now working as admin. Thanks to this command you'll never need to log into root directly again. Now, type in the following command:
ee /etc/ttys
Scroll down to line 44 that starts with "ttyv8" and make it look exactly as in shown in the screenshot (highlighted in yellow). Once this is done, press ESC to close out and save the file. When you are back at the command prompt, type in the following:
shutdown -r now
This will reboot the system. The next time FreeBSD starts; it will automatically enter the graphical environment. Lastly, I want to stress again that is not a good idea to log into KDE as root - ever. It is safer to login as yourself and su if needed.
Congratulations, you now have KDE and KDevelop up and running.
