I built NodeJS from source on an ubuntu-slim image. When you do this it requires a lot of package installs in the process, such as (for example. below is Node16 dependencies)
&& apt-get install --yes \
libstdc++6 \
...
...
&& apt-get install --yes \
binutils-gold \
g++ \
gcc \
gnupg \
libgcc-7-dev \
linux-headers-generic \
make \
python3 \
Once I have completed installing everything and configuring it, can I simply remove these build dependencies? The image has grown extensively and I need to try to clean as much fat as possible. Of course, I still want NodeJS to run my node apps.
The same kind of process happens for NodeJS 14, and I am guessing NodeJS 18.. Can we remove these build dependencies once the NodeJS is built?
After completing my building of Node14, I have found that:
npm install
ed- for example node-sass) - these are not common, so most
uses of Node do not require this.apk-get
packages that were installed is as simple as using
apk-get purge
. The example below (building node inside a Dockerfile
using shell script) gives some specifics. echo "Building from source" \
&& NODE_BUILD_PACKAGES="binutils-gold g++ gcc libgcc-7-dev linux-headers-generic make python3" \
&& apt-get install --yes ${NODE_BUILD_PACKAGES} \
...
...
[code to build node]
...
&& apt-get purge --yes ${NODE_BUILD_PACKAGES} \
&& apt-get clean \
&& apt-get autoremove --yes \
I used those three commands to clear out the build machine after building Node from source. For clarity, here is what each of those commands does:
apt-get purge
removes the packages that I installed so
that I could build Node.apt-get clean
clears the local repository of retrieved
package files that are left in /var/cache.apt-get autoremove
removes packages that were
automatically installed because some other package required them.