How To Manage Chef Cookbooks With Berkshelf

Berkshelf is a great way to manage your chef cookbooks with dependencies. If your cookbook is dependent on one or more dependencies, you can manage it without any overheads using the berkshelf way.  All you have to do is, just mention the dependent cookbooks with its version number if needed. Berkshelf will install all the dependent cookbooks from the Opscode cookbook community. In this tutorial i will explain how to set up berkshelf in your workstation and managing your cookbooks with it.

Installing Berkshelf:

Install berkshelf in your chef workstation using the following command.

Managing Existing Cookbooks:

You can manage the existing cookbook using berkshelf. 

1. CD in to your cookbook directory eg: cd cookbooks/powershell and issue the following command to create the berks and related files for your cookbook.

2. Open the berksfile that is created inside your cookbook and mention all the dependencies .In our example , for powershell, windows and chef-handler cookbooks are the dependencies. So inside the powershell berksfile you can mention the dependencies in the following format.

3.  Windows cookbook has a chef-handler dependency , but you dont have to mention it in the berksfile. It will automatically install the relevant chef-handler cookbook for the windows cookbook. You just have to mention the direct dependencies inside the berksfile.

5. By default , berksfile configures itself with the default knife.rb settings. You can check the config  in ~/.berksfile/config.json .The config.json contains a validator ,chef url settings. You can override the default settings using the following command.

4. Once the dependencies are mentioned in a berksfile, you can install the dependencies using the following command.

Creating And Managing New Cookbooks With Berkshelf:

1. Make your current directory as cookbook directory of the chef-repo, because berks command will create the cookbook and related files in the current working directory. Create a new cookbook with berkshelf with the following command. 

2. Let say, you want to create a cookbook for your new php application. Apache2 , php and Msql will the dependencies for your phpapp. So you can mention the dependencies in the berksfile of the newly created cookbook using berkshelf.

3.Install the dependencies using the berks install command. As explained earlier, the dependent cookbooks will get installed in ~/.berksfile/cookbooks folder.

In windows systems it get installed in C:UsersAdminstrator.berksfilecookbooks location

4. Once your cookbook is ready , you can upload the with all the dependent cookbooks using the following command.

The above command will upload the phpapp cookbook and all the other dependent cookbooks from the berkshelf’s cookbook folder.

5. Ther are various other commands associated with berkshelf. It will be used in different use cases. The commands are given below.

For more information, visit the official berkshelf site


Appfog is an excellent platform-as-a-service which offers free application hosting up to 2GB of memory. You can deploy…

Read more
internet of things

As we all know the internet has been around for a while. We have been communicating, sharing information, doing bank…

Read more

Cloud computing is a technology in which you can use the IT related capabilities (eg: servers, network, storage,…

Read more

Cloud Computing Tutorial Blog