BSDnexus forums

You are not logged in.

  • Index
  •  » RTFM
  •  » Creating packages from installed ports in FreeBSD

#1 2006-02-17 19:53:54

scottro
Unknown Person
From: NYC
Registered: 2005-04-04
Posts: 853
Website

Creating packages from installed ports in FreeBSD

Installing from ports often gives you more up-to-date and optimized software than does installing from packages, but ports are compiled from source.  There may be many situations where that is not optimal, for example, a heavily loaded server or a slow machine.

If you are fortunate enough to have a fast machine that isn't in production, you can also install ports on that machine.  Then, you can build a package from the port and add it to the slow machine or heavily loaded server with pkg_add.

There are many other circumstances where you might want to do this.  For example, recently I was having a somewhat obscure problem with samba.  I finally found the problem on their buglist, and was able to patch the samba code to make it work.  To avoid having to do that on each machine we have that uses samba, I then created a package, which I was easily able to install on each machine.  Otherwise, I would have had to do make extract then patch the source code on each box.

The technique is quite simple.  Suppose I have the screen utility on the fast workstation.  I also want to put it on a busy server. 

So, first, I need the version number that is installed on my workstation.

Code:

 
ls /var/db/pkg | grep screen

It gives me back the answer (as of 17 February, 2006)

Code:

screen-4.0.2_3

Now, I want to create the package

Oddly enough, the program that creates a package is called---yup, pkg_create. 

I use the -b flag to create the package.

Code:

pkg_create -b screen-4.0.2_3

I will then be returned to a command prompt.  Assuming I have write permission to the directory I was in when I ran the command, the package will be created there.  Now, doing ls | grep screen will show me

Code:

screen-4.0.2_3.tgz

I can now ssh it over to the server, and then, on the server, as root or with root privilege

Code:

pkg_add screen-4.0.2_3.tgz

In reality, I'd be using tab completion, and as long as I was in the directory of the package, I would do pkg_add scre and hit the tab key.  smile

Sometimes, packages have dependencies that have to be kept up to date.  No problem.  The pkg_create command has the -R flag.  If you use it, it will also make packages for each dependency.  The -R flag has to come before the -b flag.  For example, if I do pkg_create -bR <pkgname> I get an error message, with an exclamation point no less, saying Can't find package 'R' installed.
So, if I wanted to create a package for w3m which has boehm as a dependency

Code:

pkg_create -Rb w3m-0.5.1_3

it will create a w3m package and a boehm package.

These packages can also be used with portupgrade.  By default, if you ask portupgrade to use a package if one is available (by use of the -P flag) it first looks in /usr/ports/packages/All.  You might have to create that directory if it doesn't exist.  However, if I move my screen package into the other machine's /usr/ports/packages/All directory, then, on the second machine type

Code:

portupgrade -P screen

it will look in /usr/ports/packges/All, see the screen package and install the program from the package.  This saves compiling time and resources. 


Lastly phoenix has mentioned that if using portupgrade, it's always a good idea to use the -b flag.  Most of us, including myself, find this out the hard way.  With portupgrade, the -b flag creates backup packages of the program being installed or upgraded.  Then if the newly upgraded program doesn't work, you can simply deinstall it and replace it with the older version's package that you cleverly created with portupgrade's -b flag. 

(You could have also used the pkg_create -b to create a backup package BEFORE doing portupgrade, but that seems a waste of effort--portupgrade's -b flag does it for you.   The point is that both will create a package of the program)

If you fail to do this, and the upgraded program doesn't work, then usually, your only option is to use the portdowngrade utility, which, although not difficult, takes much more work than simply deleting the newly upgraded, not working properly package and replacing it with the older version from a package.

It can save an enormous amount of time, especially if you're installing a new machine.  Rather than having to download and compile everything, assuming they're running the same version of FreeBSD you can simply create packages from an existing machine and install them with pkg_add. 

Obviously (hopefully) the two machines should be running the same version of FreeBSD.  Packages created on a 6.x machine will seldom work on one running 5.x and vice versa.

Last edited by scottro (2006-02-17 19:59:39)


<@andre> i would be so much more efficient if i wasn't so stupid

Offline

 

#2 2006-02-18 02:31:31

thermite
Member
From: Michigan
Registered: 2005-04-13
Posts: 149
Website

Re: Creating packages from installed ports in FreeBSD

is there any noticible advantage other than speed

Code:

ls /var/db/pkg | grep screen

to

Code:

 pkg_info | grep screen

Offline

 

#3 2006-02-18 02:56:12

scottro
Unknown Person
From: NYC
Registered: 2005-04-04
Posts: 853
Website

Re: Creating packages from installed ports in FreeBSD

Not that I know of.  Remember, in Unix there's always more than one way to do thing.  The corollary is that someone will think your way is stupid.  smile

I didn't even think of pkg_info | grep screen till you posted it, then I did both.  ls /var/db/pkg seems much faster.


<@andre> i would be so much more efficient if i wasn't so stupid

Offline

 

#4 2006-02-18 03:44:22

phoenix
Member
Registered: 2005-03-29
Posts: 294

Re: Creating packages from installed ports in FreeBSD

thermite wrote:

is there any noticible advantage other than speed

Code:

ls /var/db/pkg | grep screen

to

Code:

 pkg_info | grep screen

Depends what you are looking for.  If all you need is the name and version, there's no real difference.  If you want more than, that, nicely formatted, then pkg_info is what you want to use.

Offline

 

#5 2008-01-08 02:27:03

lenix
New member
From: Hamburg, Germany
Registered: 2008-01-08
Posts: 1
Website

Re: Creating packages from installed ports in FreeBSD

Code:

pkg_info -Ix screen

offers both, speed and details :-)

Offline

 

#6 2008-01-21 20:09:26

hydra
New member
From: Europe.sk
Registered: 2006-08-17
Posts: 5

Re: Creating packages from installed ports in FreeBSD

pkg_info is slow for the first time run, but then it's faster I believe wink

Offline

 
  • Index
  •  » RTFM
  •  » Creating packages from installed ports in FreeBSD

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson