# Install pkg on fresh FreeBSD via shell script



## olejak (Feb 19, 2014)

Hi

I'm trying to install pkg via a shell script on a fresh install FreeBSD 10. I'm new to shell scripting and I tried to search the forum and elsewhere but no luck. My script is a simple one just to prepare the server with some basic set up. I want to use `pkg` to install but it needs to be install separately.


```
# pkg
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]:
```

I need to get this "y" pressed so I tried this.


```
if [ -f /usr/local/sbin/pkg ]; then
	/usr/local/sbin/pkg update
else
	pkg < /usr/bin/yes
fi
```

But doesn't work. How do I get that question answered with a "y"?

pkg() don't seem to give the answer.

Any help will be appreciated.

Cheers


----------



## SirDice (Feb 19, 2014)

olejak said:
			
		

> How do I get that question answered with a "y"?


Use the -y option. You can also fetch the package for it, extract it and use the included pkg-static to register itself.


----------



## junovitch@ (Feb 21, 2014)

This is what I use in my NanoBSD build script.  It will work even for the initial bootstrapping of pkg.

```
env ASSUME_ALWAYS_YES=YES pkg -c ${NANO_WORLDDIR} install ports-mgmt/pkg
env ASSUME_ALWAYS_YES=YES pkg -c ${NANO_WORLDDIR} install shells/bash
... # more packages follow ...
```


----------

