# Compiling and installing a port as an unprivileged user



## kpedersen (Mar 7, 2011)

Hello,

I am trying to see if I can create a prefix in my home directory to hold a different (older) version of a ports tree snapshot. Is this possible?


```
# Set required variables
$ export PREFIX=/home/kpedersen/local
$ export PORTSDIR=/home/kpedersen/ports
$ export PORT_DBDIR=/home/kpedersen/portsdb

# Compile and install port
$ cd /home/kpedersen/ports/shells/bash
$ make
$ make install
```

This gets close but unfortunately I have not found a way to specify the pkg db (/var/db/pkg) and so it conflicts with the current ports tree.

It also asks for root privilege on the make install (so it can write to the pkg db and register the package)

This would be awesome if it would work because it would allow me to easily keep a personal prefix containing old unmaintained ports without the need for a jail.

Best Regards,


----------



## SirDice (Mar 7, 2011)

kpedersen said:
			
		

> I am trying to see if I can create a prefix in my home directory to hold a different (older) version of a ports tree snapshot. Is this possible?


From pkg_add(1):


> The environment variable PKG_DBDIR specifies an alternative location for the installed package database, default location is /var/db/pkg.


----------



## kpedersen (Mar 7, 2011)

Cool, thanks.

I never thought to look at the pkg_add manpage because I thought it was the ports collection that installed the port rather than package add.

I do still have one problem to fix and that is it still asks for my root password even though I do not need to write anywhere other than my home directory.


```
===> Switching to root credentials for 'install' target
Password:
```

Is this hard coded? Is there any way to prevent the root request?


----------



## SirDice (Mar 7, 2011)

kpedersen said:
			
		

> I never though to look at the pkg_add manpage because I thought it was the ports collection that installed the port rather than package add.


It's also mentioned in ports(7).



> I do still have one problem to fix and that is it still asks for my root password even though I do not need to write anywhere other than my home directory.
> 
> 
> ```
> ...



Good question, no idea actually. You might want to have a look in /usr/ports/Mk/bsd.port.mk.


----------



## kpedersen (Mar 7, 2011)

Looking at bsd.port.mk I noticed


```
...
!defined(INSTALL_AS_USER)
...
```

so I tried


```
export INSTALL_AS_USER=1
```

And it did the job 

Thanks SirDice, for your help.

Edit:
Just found this mail here: http://www.mail-archive.com/freebsd-questions@freebsd.org/msg31323.html

Which is exactly what I have just done... lol


----------

