7 Carthage Terminal Commands to Bookmark

Rick Owers
Remote iOS Dev
Published in
4 min readFeb 18, 2020

Carthage has been the dependency management tool of choice at my last few jobs. While we sometimes use Cocoapods due to 3rd party requirements and lack of Carthage support, it has typically been a goal to use Carthage exclusively for our dependency management needs.

Anyone that has used Carthage knows that the simplicity that Carthage offers in creating and adding frameworks to a project can also come with some weird headaches that baffle even the most experienced iOS developer. Working through circular dependencies, incompatible swift versions, 3rd party dependency issues (some teams just suck at versioning), or simply a carthage updatethat just hangs, these can all make a “simple” process turn into a deep dive into Github issues and the stackoverflow abyss.

The following are Carthage terminal commands I’d suggest bookmarking for future use. They have come in handy for my teammates and I, and I’m sure you will use them as well.

NOTE: [update|bootstrap] is used to denote that the command can be written with either the update or bootstrap command. However, you cannot run the command with the [update|bootstrap] in the terminal. This will be obvious for most developers, but if you are new to Carthage, I don’t want to cause any confusion.

1. Carthage platform specification

carthage [update|bootstrap] --platform ios

Utilizing --platform ios will speed up your update and bootstrap processes by ensuring you only bring in the iOS framework versions. Without this additional flag (Carthage CLI flags or parameters start with the --), you could bring in watchOS, tvOS, or macOS versions of the framework which add considerable time to your overall build process.

NOTE: A flag or a parameter in a Carthage terminal command allows for additional behaviors to occur when running the base command. They always start with -- and you can use multiple flags/parameters in a single command.

2. Caching Carthage dependencies

carthage [update|bootstrap] --cache-builds

If you have ever leveraged a Carthage dependency that takes 10 minutes to build (it’s less uncommon than you’d think), this --cache-builds command will make you a more productive developer during future update and bootstrap commands. Instead of running through the entire Carthage build process, the --cache-builds option knows that it can leverage the already existing build that you have in your Carthage sub folders. This can easily turn a ten minute process into a sub 10 second process.

3. Updating single Carthage dependencies

carthage update FrameworkName

Many times, you are only needing to update a single dependency, but if you are not careful you will find yourself waiting for all the dependencies to update instead of just the one you need. There are some nuances to this command as you will see other dependencies get fetched and downloaded, but the build process should only occur against the single dependency.

4. Require Carthage to build from source code

carthage [update|bootstrap] --no-use-binaries

Many frameworks will provide a binary format of its framework. The benefits of this is that the source code is pre-compiled and therefore does not need to run through the whole build process. This can help speed up the time needed to run a project update or bootstrap. The downside is that sometimes the binary will not be compatible with your compiler version. In this case, you can always revert back to building the project from its source code that is checked out in the Carthage folder.

5. Get additional Carthage log information

carthage [update|bootstrap] --verbose

Sometimes you just need more information to understand why Carthage is not building correctly. Using this flag will allow you to get way more information then you’ll even need on a regular basis, but it can also help to debug your current issue.

6. Check that your custom Carthage framework can build

carthage build --no-skip-current

I’ve worked on a project that would build properly inside the Xcode project file, but Carthage as a dependency manager could not properly build the project. Running this command on your custom frameworks can ensure that they will build properly within another host application’s codebase.

7. Blow it all away and start again

rm -rf Carthage ~/Library/Caches/org.carthage.CarthageKit ~/Library/Developer/Xcode/DerivedData

This command has been very useful when nothing seems to work to get Carthage to properly update. Over time, Carthage builds up cached versions of frameworks and references in a few locations. What this command does, is wipes everything away to a fresh state.

When running this command, it assumes that you are inside of your projects root directory (where the project’s Carthage folder is located). Once completed, your local Carthage folder will be empty, your DerivedData will be empty, and your cached CarthageKit folders will be empty.

Final Thoughts

There are many more commands that you can leverage, and the Carthage Github repository has a ton of great information that can help get you get setup. Go checkout their extremely detailed Readme file as well as their Documentation folder which contains some great information about framework artifact references inside of your Cartfile.

--

--

Rick Owers
Remote iOS Dev

Writer focusing on my career and life experiences: developer, engineering manager, family man, beach lover and dreamer of financial independence.