Packages generated by Traveling Ruby can be large, but you can reduce the size of your packages by many megabytes by removing unnecessary files.
You can typically safely remove the following files:
# Remove tests
rm -rf lib/vendor/ruby/*/gems/*/test
rm -rf lib/vendor/ruby/*/gems/*/tests
rm -rf lib/vendor/ruby/*/gems/*/spec
rm -rf lib/vendor/ruby/*/gems/*/features
rm -rf lib/vendor/ruby/*/gems/*/benchmark
# Remove documentation
rm -f lib/vendor/ruby/*/gems/*/README*
rm -f lib/vendor/ruby/*/gems/*/CHANGE*
rm -f lib/vendor/ruby/*/gems/*/Change*
rm -f lib/vendor/ruby/*/gems/*/COPYING*
rm -f lib/vendor/ruby/*/gems/*/LICENSE*
rm -f lib/vendor/ruby/*/gems/*/MIT-LICENSE*
rm -f lib/vendor/ruby/*/gems/*/TODO
rm -f lib/vendor/ruby/*/gems/*/*.txt
rm -f lib/vendor/ruby/*/gems/*/*.md
rm -f lib/vendor/ruby/*/gems/*/*.rdoc
rm -rf lib/vendor/ruby/*/gems/*/doc
rm -rf lib/vendor/ruby/*/gems/*/docs
rm -rf lib/vendor/ruby/*/gems/*/example
rm -rf lib/vendor/ruby/*/gems/*/examples
rm -rf lib/vendor/ruby/*/gems/*/sample
rm -rf lib/vendor/ruby/*/gems/*/doc-api
find lib/vendor/ruby -name '*.md' | xargs rm -f
# Remove misc unnecessary files
rm -rf lib/vendor/ruby/*/gems/*/.gitignore
rm -rf lib/vendor/ruby/*/gems/*/.travis.yml
# Remove leftover native extension sources and compilation objects
rm -f lib/vendor/ruby/*/gems/*/ext/Makefile
rm -f lib/vendor/ruby/*/gems/*/ext/*/Makefile
rm -f lib/vendor/ruby/*/gems/*/ext/*/tmp
find lib/vendor/ruby -name '*.c' | xargs rm -f
find lib/vendor/ruby -name '*.cpp' | xargs rm -f
find lib/vendor/ruby -name '*.h' | xargs rm -f
find lib/vendor/ruby -name '*.rl' | xargs rm -f
find lib/vendor/ruby -name 'extconf.rb' | xargs rm -f
find lib/vendor/ruby/*/gems -name '*.o' | xargs rm -f
find lib/vendor/ruby/*/gems -name '*.so' | xargs rm -f
find lib/vendor/ruby/*/gems -name '*.bundle' | xargs rm -f
# Remove Java files. They're only used for JRuby support
find lib/vendor/ruby -name '*.java' | xargs rm -f
find lib/vendor/ruby -name '*.class' | xargs rm -f
Depending on which gems you use, there may be more files that you can remove.
What I typically do is to run find lib/vendor/ruby/*/gems | less
to inspect which files exist, and try to identify the files that I think can be removed.
To focus on non-Ruby files, I run find lib/vendor/ruby/*/gems -type f | grep -v '.rb$' | less
which filters out all .rb files.
Here are a few examples:
- Many gems that contain a Rakefile only need those Rakefiles for the purpose of developing those gems. In many cases, you can safely remove those Rakefiles without impacting your application. In a similar fashion, the
task
directory within those gems (which typically contain further Rake tasks) can also be removed. - The
nokogori
gem contains thesuppressions
directory. This directory contains Valgrind suppression files, so if you never use Valgrind (which is very likely) then you can remove that directory too. - The
nokogori
gem also contains theports
directory. This directory is only used during compilation of the native extension, so it can be removed. - The
rack
gem contains acontrib
directory which appears to be only relevant for documentation purposes, so it too can be removed. - The
rugged
gem contains avendor
directory which contains the libgit2 source code, but this directory is only used during compilation of the native extension, so it can be safely removed.
When in doubt, you should inspect the gem's source code to check how a file is used and whether you can remove it.
Ruby support many encodings that are seldomly used. Most applications only use ASCII and UTF-8. But Ruby also supports UTF-16, UTF-32, various Chinese, Japanese and Korean encodings, etc. Usually you can get rid of everything besides ASCII and UTF-8:
rm -f lib/ruby/lib/ruby/*/*/enc/cp949*
rm -f lib/ruby/lib/ruby/*/*/enc/euc_*
rm -f lib/ruby/lib/ruby/*/*/enc/shift_jis*
rm -f lib/ruby/lib/ruby/*/*/enc/koi8_*
rm -f lib/ruby/lib/ruby/*/*/enc/emacs*
rm -f lib/ruby/lib/ruby/*/*/enc/gb*
rm -f lib/ruby/lib/ruby/*/*/enc/big5*
rm -f lib/ruby/lib/ruby/*/*/enc/windows*
rm -f lib/ruby/lib/ruby/*/*/enc/utf_16*
rm -f lib/ruby/lib/ruby/*/*/enc/utf_32*
Very few applications need support for transcoding strings from one encoding to another, besides ASCII and UTF-8. You can get rid of transcoding support as follows:
rm -rf lib/ruby/lib/ruby/*/*/enc/trans
Most likely your application does not need RDoc during runtime. You can remove that as follows:
rm -rf lib/ruby/lib/ruby/*/rdoc*