# Removing /usr/local



## TroN-0074 (Apr 4, 2012)

Every time I install a new application /usr/local seems to become larger. Would it be safe to remove whatever is inside that directory? I have a really small hard drive so I need to do whatever to maintain it lean. I will appreciate all advice.

Thank you.


----------



## SirDice (Apr 4, 2012)

All ports/packages install their files in /usr/local/. So, no, you can't simply remove it.


----------



## tangram (Apr 4, 2012)

What you can do is go over your installed applications and uninstall what you don't use anymore.


----------



## fonz (Apr 4, 2012)

TroN-0074 said:
			
		

> Every time I install a new application /usr/local seem to become larger.


Of course. The application has to go somewhere...

I'm guessing you're coming from a Linux environment. Whereas (most distributions of) Linux put(s) applications all over the place (e.g. /usr, /usr/local, /opt, /app, etc. etc.), FreeBSD observes a rather strict division between the base system and third-party applications. The latter are almost always placed in /usr/local. In other words: when you install an application on a FreeBSD system, /usr/local is where it goes.

Fonz


----------



## Zare (Apr 4, 2012)

> Every time I install a new application /usr/local seem to become larger



Isn't it logical that if you install a package, and /usr/local grows larger, that package has been installed to /usr/local?


----------



## TroN-0074 (Apr 4, 2012)

Thank you for the replies. Sure make sense that the more apps I installed the fatter my file system will become. I just thought that when compiling a piece software the compiler was also shutting out some garbage files that I could remove. Like I said I have a rather small hard drive and I need to keep an eye on it before it becomes full.

Thank you.


----------



## Zare (Apr 4, 2012)

> I just thought that when compiling a piece software the compiler was also shutting out some garbage files that I could remove.



In ports system, progress files and final build "product" are kept in work subdirectory in port directory. It will not be deleted unless specified otherwise. The command is : `# make clean`. If you run it inside port directory, it'll clean that port. If you run it on whole ports tree (eg inside /usr/ports/), it will clean everything, but it's somewhat slow. If you don't have many ports installed (let's say up to 50), the following script could be useful :


```
#!/bin/sh

for i in `find /usr/ports -name work -type d`
do
    cd `echo "$i" | sed 's/\/[^\/]*$/\//'`
    make clean
done
```

The source files needed for port builds are kept inside /usr/ports/distfiles/. In case of cheap bandwidth vs expensive storage, you should periodically delete everything from that directory.

Ports tree itself has around ~ 870MB. Move it to somewhere and mount via NFS. Or compile ports on another platform-compatible computer into binary packages, copy and install. World source tree is also large (~ 700MB). In essence, perform your compilations elsewhere, so you don't need a whole build environment on-board.


----------



## SirDice (Apr 5, 2012)

Zare said:
			
		

> If you don't have many ports installed (let's say up to 50), the following script could be useful :
> 
> 
> ```
> ...



`# rm -rf /usr/ports/*/*/work`
Is a lot faster and simpler.


----------



## fmw (Apr 5, 2012)

SirDice said:
			
		

> `# rm -rf /usr/ports/*/*/work`
> Is a lot faster and simpler.



What's the difference between that and `# portsclean -C`
?


----------



## wblock@ (Apr 5, 2012)

portsclean may not be present, it is part of ports-mgmt/portupgrade.


----------



## fmw (Apr 6, 2012)

Oops, my bad. I've been using it so casually that I failed to see the obvious...


----------

