sperea.es
Published on

One Month Working with FreeBSD

Authors

As an avid tinkerer, I have been working with FreeBSD on my laptop for some time now. I simply wanted to experience what it was like to work with this system, and truth be told, after a month of use, I am quite pleased. I hardly miss anything from Linux, and I have a much faster system that perfectly meets my professional needs.

People often approach me when they see me working, curious about it, as it is not common to see someone developing with a BSD system. People usually wonder if it is overly complicated to install or if they will find support for the tools they commonly use.

Well, in this article, I will try to summarize my initial impressions.

When someone mentions FreeBSD, they probably think of servers and network-attached storage (NAS) devices. Indeed, FreeBSD is an excellent operating system for those purposes. However, there are some myths claiming that FreeBSD is not suitable for desktop environments and specifically for software developers (unless you have a Mac).

freebsd

The truth is that FreeBSD has come a long way in this regard. It is a modern, complete, and robust operating system. Both system administrators and software developers can use it for their daily tasks, especially if they want to experience working with a pure Unix system or if they are not particularly fond of Windows or Mac.

What languages can you program with on FreeBSD?

The most important question for software developers is whether their programming language is compatible with FreeBSD.

Well, all popular programming languages are supported on FreeBSD. There really is no limit.

Do you want to build your new website with Node.js, PHP, or Python? FreeBSD supports them all. If you are looking for low-level programming with languages like Go or Rust, FreeBSD has you covered. You will also find updated versions of clang and gcc in the ports. You can even work with Java through OpenJDK or C# through Mono.

The great thing is that in most cases, FreeBSD's native package manager, pkg, allows you to install the necessary compiler. For example, for PHP, Ruby, or Python, numerous packages are provided through pkg. And if for some reason you want to install something that is not available through pkg, you can do it through FreeBSD's ports.

bashCopy code

pkg install py{27,36}-game

This will allow you to manage all the packages installed on your system. I haven't seen a simpler and cleaner package manager, to be honest. If you want to install WordPress, you just need to type:

bashCopy code

pkg install wordpress

FreeBSD's ports are a package management system for the FreeBSD operating system. They consist of a set of scripts and configuration files that facilitate software installation.

Each port contains information on how to compile and configure a specific package to make it work on FreeBSD. Users can download ports from the official FreeBSD repository and use them to install additional software on their system.

Regarding running software from other systems like GNU/Linux, FreeBSD has native support for running it through a system called the "Linux compatibility layer," which allows Linux applications to run on FreeBSD without the need for a virtual machine or a complete GNU/Linux operating system. It is often cautioned in forums that this does not guarantee full compatibility with all Linux applications, and some may have issues or not work properly. However, I can affirm that I have not encountered any problems with them to date, and everything runs even more smoothly than on Ubuntu.

Development Environments

Another important question for software developers is whether their favorite Integrated Development Environment (IDE) will work on FreeBSD. When we think of a development environment, we might typically associate Unix with Vim and Emacs. However, in 2023, that's no longer the case, as you will also find more modern IDEs for your work on FreeBSD, such as:

  • Eclipse
  • Sublime Text
  • PyCharm (free and commercial versions)
  • IntelliJ (community and commercial versions)

If your IDE does not directly support FreeBSD, you can always try running it using Linuxulator, a Linux compatibility layer on FreeBSD.

You also don't have to worry about your code version control system. You will find all popular open-source version control systems, such as Git, Mercurial, or SVN.

An excellent way to maintain your environment and test your software is by using "jails."

If you need to have multiple versions of your application for different clients or multiple databases, then jails are what you should use. You can also combine them with ZFS and easily deploy your changes to production. Managing jails has never been easier using iocage or ezjail.

Sometimes jails are not enough, and we need to work with different operating systems. FreeBSD has that covered as well. If you are looking for lightweight virtualization of any modern operating system such as Windows, Linux, OpenBSD, NetBSD, or even FreeBSD, bhyve is the way to go.

Folder Organization

In FreeBSD, the directory structure is orderly and easy to understand. If you come from a Linux environment, you will quickly get used to it.

For example, FreeBSD-specific binaries that come with the operating system are located in /bin and /sbin, while additional binaries are found in /usr/bin and /usr/sbin. Furthermore, all third-party software is installed in /usr/local/bin and /usr/local/sbin. This makes it easy to maintain and organize the system.

A Discovery: DTrace

DTrace is a powerful tool for software developers that enables dynamic tracing of software. With just a few lines of D code, you can view program traces, analyze performance, track function entry, and much more.

Additionally, DTrace has the ability to generate flame graphs, which help identify the most frequent code paths. This tool is especially useful for debugging low-level applications and is natively available in FreeBSD.

Other useful tools for developers in FreeBSD include procstat, ktrace/kdump, pmccontrol, and pmcstat. For low-level debugging, lldb is an excellent alternative to gdb.

Interesting Technologies You'll Find in FreeBSD

FreeBSD is an operating system that has pioneered many technologies, such as ZFS or containers. It is POSIX-compliant (remember that Linux is not a pure UNIX, but a clone that doesn't fully adhere to this standard), but it also introduces or integrates many excellent APIs that the rest of the world has yet to fully adopt.

One example is kqueue, a tool that provides an efficient pipe system for input and output events between the kernel and the user. It is much more efficient, especially when monitoring events on a large number of file descriptors.

Speaking of descriptors, we should also mention process descriptors, a new way to add a reference (descriptor) to the process. Process identifiers (PID) used by many operating systems are sometimes not entirely reliable. Between checking the process state and sending signals, many things can happen in the operating system, and theoretically, the PID can be used by another process at that moment, causing problems or undesired hangs. Process descriptors solve these problems by providing a reliable reference to attach to the process. If the process has terminated, you will still have a reference to gather information about it.

There is also a sandboxing technique in FreeBSD called Capsicum. Capsicum is a capability-based security mechanism. Capability-based security means that processes can only perform actions that have no global impact. For example, processes cannot open files using their absolute path or open network connections. The idea is to protect your application by considering process privilege separation.

Furthermore, to ensure the security of your applications, you can also consider using CloudABI. CloudABI takes a POSIX function, adds capability-based security, and removes anything incompatible with it. This forces software developers to use very specific sets of functions in their applications, but it increases the security of the application.

In summary, and to keep this topic concise, FreeBSD is working on many interesting technologies that will likely become the standard in other operating systems like Linux in the future. If you want to stay up to date, you should take a look at this operating system.

How's the Documentation and Community Support?

FreeBSD is known for having good documentation, and when it comes to software development, it's no different.

How many times have you searched on Google for an ASCII table? Well, in FreeBSD, by default, you have a man page for it: ascii(7). The same goes for architecture/language-specific things like:

  • arch(7) - architecture-specific details like pointer size, numbers, or pages.
  • operator(7) - precedence and order of evaluation for operators in C and C++.
  • zstyle(9) - the best C style you will find, FreeBSD has been using it for decades.
  • hier(7) - to understand the Unix directory structure.

All of this makes our work as programmers much easier.

As for the community, it must be said that it is by no means as large as the Linux community. And that can be a problem. Nevertheless, the FreeBSD community is very active, with various mailing lists and newsgroups, as well as a large number of user groups in different parts of the world. I even believe there is still an active community on IRC. Moreover, many FreeBSD developers maintain blogs where they share details of their work on the operating system.

The truth is, there are not as many people around this system providing help, but it is also true that those who are generally have a high technical profile and are very good at problem-solving. However, if you are looking for a community like Linux's, you can forget about it. Dealing with FreeBSD's issues will remind you of the early days of Linux, in some cases. It's only for restless minds.

Conclusion

The possibilities for software development with FreeBSD are limitless. This operating system has a plethora of interesting features like Jails, bhyve, ZFS, and DTrace that make life easier for software developers. It is incredibly fast, and you will notice the difference in your day-to-day work---a great way to give a second life to a slightly outdated laptop.

Additionally, it boasts highly useful in-system documentation, not to mention the abundance of third-party software available.

At first, it may be a bit challenging, but trying to learn it can be an interesting experience, and once you get used to it, you may never want to switch back.