How can I replicate the Travis CI build environment on my local machine?

Now, you can replicate a build machine by examining it from a build script, uploading custom stuff somewhere (I did that to diagnose problems with their stock scripts) and arranging non-custom stuff the same way.

Then you should be able to somehow use https://github.com/travis-ci/travis-build to generate a job script from .travis.yml and run it in that replicated environment…

But if getting a project to build on a local machine is too hard for you, this will likely be too hard, too.