How to Set Up an Environment as a Default Dev Hub in Salesforce DX
In order to create a scratch org in Salesforce DX, we need to configure a Dev Hub environment to which our new scratch org will be linked. There are two ways to do this:
- Setting the -v flag within the command for creating our scratch org as follows:
In this example, the value DevHub is the alias or username of the Dev Hub environment from which we want to create our scratch orgs.sfdx force:org:create -s -f config/project-scratch-def.json -v DevHub
The drawback of this method is that we need to specify this flag every time we want to create a new scratch environment. - Configuring a project-wide configuration variable by setting the defaultdevhubusername variable as follows:
Now we can run the command to create a scratch org without explicitly specifying our Dev Hub environment's name.sfdx force:config:set defaultdevhubusername=MyDevHub
sfdx force:org:create -s -f config/project-scratch-def.json