# What is the best way to remove all packages and start over?



## mdg (May 28, 2012)

Running 9.0 Stable. 

Want to completely remove all installed packages and start over and install just a few packages. I use portmaster to maintain my packages. Seems to me this is what I should do.


 Update the ports tree.
 Run pkg_delete
`#  pkg_delete -a`
 Back up /usr/local/etc/
 Clean out directories 
`#  rm -Rf /var/db/pkg/*  /usr/local/*  /usr/ports/distfiles/*`

Reinstall portmaster and proceed from there to install the ports I need.

Does that seem correct?  Am I missing any steps?


----------



## gkontos (May 28, 2012)

Why don't you just reinstall the OS and start over with a fresh system?


----------



## graudeejs (May 28, 2012)

mdg said:
			
		

> Running 9.0 Stable.
> 
> Want to completely remove all installed packages and start over and install just a few packages.
> I use portmaster to maintain my packages. Seems to me this is what I should do.
> ...



I prefer to 

```
# rm -Rf /var/db/pkg/*
# rm -Rf /usr/local/* # except etc
```

if /usr/local/ is on a separate partition, back up etc and format the partition.


----------



## wblock@ (May 28, 2012)

mdg said:
			
		

> Running 9.0 Stable.
> 
> Want to completely remove all installed packages and start over and install just a few packages.
> I use portmaster to maintain my packages. Seems to me this is what I should do.
> ...



Pretty much.  The portmaster(8) man page has a procedure at the end that shows doing that.


----------



## UNIXgod (May 28, 2012)

gkontos said:
			
		

> Why don't you just reinstall the OS and start over with a fresh system?



That's a lot of work for just removing installed ports. Unless the system is foobarred for some reason there is no reason to start over with a fresh install.


----------



## graudeejs (May 28, 2012)

wblock@ said:
			
		

> Pretty much.  The portmaster(8) man page has a procedure at the end that shows doing that.



I wouldn't recommend `# rm -Rf /usr/ports/distfiles/*`
HDD space is very che*a*p these days. Use /usr/ports/distfiles/ for cache.
Next time you update or reinstall there will be much fewer tarballs (tar archives) to download.
After you're done installing run `# portmaster -y --clean-distfile` (you may remove -y if you want to pick tarballs that you want to remove). This will remove obsolete tarballs.


----------



## gkontos (May 28, 2012)

UNIXgod said:
			
		

> That's alot of work for just removing installed ports. Unless the system is foobarred for some reason there is no reason to start over with a fresh install.



Installing takes a few minutes, even cli. If you back up some important files in /etc & /usr/local/etc then you pretty much have everything you need.


----------



## UNIXgod (May 28, 2012)

gkontos said:
			
		

> Installing takes a few minutes, even cli. If you back up some important files in /etc & /usr/local/etc then you pretty much have everything you need.



Not really a few minutes. Everyone has different setups. You still have to recompile your kernel and patch any security issues that have been disclosed since the initial install as well as a countless other customizations which may have been deployed depending on the setup the OP has (jails, zfs, hardware etc.). This isn't some linux distro where world and ports are considered the same and re-installs are suggested to fix breakage. There is no reason to blow away a system when all the OP needs it to blow away the ports cleanly. It's really a bad policy and is not recommended.


----------



## jb_fvwm2 (May 29, 2012)

gkontos said:
			
		

> Installing takes a few minutes, even cli. If you back up some important files in /etc & /usr/local/etc then you pretty much have everything you need.



Not sure why the OP wants to remove *most* packages, but I recall the following from
updating python etc:

```
cd /var/db/pkg
ls -lac | grep py26
```
... adapted to this use until the number of ports is pared down...

```
cd /var/db/pkg
ls -oSr  # the largest installs *may* be listed at the bottom
pkg_delete -f ... 
pkg_delete -f ...
```
...Seems like it would take only a few minutes rather than hours.


----------



## gkontos (May 29, 2012)

UNIXgod said:
			
		

> Not really a few minutes. Everyone has different setups. You still have to recompile your kernel and patch any security issues that have been disclosed since the initial install as well as a countless other customizations which may have been deployed depending on the setup the OP has (jails, zfs, hardware etc.).
> This isn't some linux distro where world and ports are considered the same and re-installs are suggested to fix breakage. There is no reason to blow away a system when all the OP needs it to blow away the ports cleanly. It's really a bad policy and is not recommended.



The OP asked for a way to wipe out all ports and start over. Before we provide an answer we have to think why would someone want to do something like this.


He is playing on a production server (Highly unlikely)
He is a power user with a complex customized KERNEL including exotic hardware and a few hundred jails (Highly unlikely)
He is learning FreeBSD, installed a few hundred ports and now wants to keep only a few.
 
Your Linux/FreeBSD comparison is really off topic here. I also wonder why you think that a reinstall is a bad policy. Unless of course you believe that someone is born a FreeBSD power user and doesn't have to break a few systems in the way.


----------



## UNIXgod (May 29, 2012)

gkontos said:
			
		

> I also wonder why you think that a reinstall is a bad policy. Unless of course you believe that someone is born a FreeBSD power user and doesn't have to break a few systems in the way.



I don't believe the Linux/FreeBSD comparison is off topic as I have seen first hand misinformation passed down from individual to individual in a classic Dunningâ€“Kruger effect.

The OP didn't break the system. If that was the case it would be imperative, whether for data retention or educational purposes, to exhaust every recovery technique before suggesting re-installation.

This has nothing to do with power users or new users. It has to do with properly distilling information on a help forum to facilitate the proper procedures which may not have been documented or could be obfuscated in it's current documented form.


----------



## gkontos (May 30, 2012)

@UNIXgod,

I am stopping this here because it is getting off topic and it appears to become personal. Something which clearly doesn't help the purpose of this forum.


----------

