Goal
If you read this article and follow the steps thoroughly, you should end up with a well-equipped system on macOS that will make developing with V as easy as possible.
Overview
It is tedious to navigate to several websites, download the executables for every tool we need, and install them separately. Unless they are allowed to check for updates, the installation of newer versions must be done manually as well. We present a simpler approach – using a command-line installer, specifically Homebrew (https://brew.sh/) for installing and updating all our software from a single source.
Followed by Homebrew, we install several critical software components that we will use all the time. They are Xcode. git, and VS Code.
Next, we get to installing V from source with our newly acquired tools. We finish up with a test project to ensure that everything is working as intended.
Opening Terminal.app
In order to install V and set up our development environment on macOS, we need to first open the Terminal app to access a command-line interface (or CLI). To open this app, open the macOS Spotlight by typing ⌘+Enter, and then search for “Terminal.app”. Once you see the app show up in the search results (which should be instantaneous), press Enter. You should now see the Terminal window open like this:
Our terminal in the screenshot above has a theme installed from Oh My Zsh, which you can install and use as well, or you can simply use the barebones Terminal setup which comes with the system by default.
If you have any issues on how to open the Terminal app, please see Apple’s support documentation.
Installing Homebrew
Homebrew is a community-run package manager that allows installation of common software from the command-line, which aren’t shipped with the system tools by default. In order to install, first, we navigate to https://brew.sh/ and copy & paste the installer script code under “Install Homebrew”.
Paste the following code from the Homebrew website into the Terminal we opened up earlier and press Enter:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Note that in order to install Homebrew, your user will need to have sudo access (i.e., your user needs to have Administrator privileges). If your user doesn’t have these privileges and you try to install Homebrew, you may see the following error:
In order to resolve this issue, either sign in as an administrator or set the current user to have administrator privileges. You can read more about how to do this on Apple’s documentation or other support forums online.
For our tutorial, we’re simply going to sign in as the admin user which is already set up for this purpose.
Once you paste the installer command and press Enter, you’ll be asked for your password for Homebrew to install:
Once you enter your password, you’ll now see output that looks like this:
This is simply boilerplate information from Homebrew, showing you which files and directories will be created and set up for installation purposes. Go ahead and press Enter to continue the installation process.
After this, you should see a lot of output from Homebrew, indicating its installation progress. If you have any issues installing Homebrew, please file an issue on their Github project.
Hopefully, the installation process will finish without issue and you should see the following output:
If you wish, you can also disable Homebrew’s builtin analytics which are enabled by default. You can do this by running the command brew analytics off
and you can verify the status of this by simply running brew analytics
in the Terminal:
You can read more about Homebrew’s analytics in their documentation.
Installing Xcode
Now that we’ve installed Homebrew, we can install another tool which we need to install V. macOS ships important development tools with its flagship editor known as Xcode. We can install Xcode by searching for it on the App Store like so:
Once you see it, click the blue button labeled “Get” and Xcode will begin installing. It may take a few minutes depending on your internet connection. This will give us helpful development tools like make
, clang
, and more.
Installing Git
One critical component that we will always need is a software called git
. We won’t install it through an installer downloaded from the website, but instead we’ll use Homebrew. If you want more information on Git and also a good tutorial on it, we recommend checking out their documentation: https://www.git-scm.com/doc
This is very simple to do with Homebrew. Simply type brew install git
in the Terminal and press Enter:
Check software versions
As a quick sanity check, we’ll go ahead and verify the versions of the software we just installed to make sure everything’s working properly before we proceed to our V installation. To verify, run the following commands in the screenshot below and check if your output is similar to the output below:
In this screenshot, we’re running git –version
to check the version of our git installation from Homebrew; cc –version
to check the version of our C compiler from Xcode; and make –version
to check the version of Make that we have also from Xcode. The commands afterwards simply show where the tools are installed in your filesystem. Your output doesn’t have to be exactly the same, but it should be similar.
Optional: Installing Visual Studio Code
The next software comes from Microsoft, and is called ‘Visual Studio Code’. It is a spiritual successor of the Atom editor from GitHub and now has become a very popular editor among developers.
You can install VS Code either directly from their website, like so:
Or, alternatively, you can also install it from Homebrew by using Homebrew Casks.
Simply run brew install --cask visual-studio-code
in the Terminal:
Whether you choose to install directly from VS Code’s website or via Homebrew Cask, you should now have a functional installation of Visual Studio Code.
We finally get to install V!
We have all the components in place. Now we can install V from source:
-
Open Terminal.
-
Create a new folder to install V in. For example, try
mkdir v_projects
. -
Navigate to the folder using
cd v_projects
. -
Clone the V repository using
git clone https://github.com/vlang/v
. -
Navigate into this directory:
cd v
. -
Run
make
which will compile V for macOS. -
Run
sudo ln -s ~/v_projects/v/v /usr/local/bin/v
to add V to your command-line path. This will take effect the next time you open the Terminal. -
If /usr/local/bin isn’t already in your PATH, follow this guide, and then quit and re-open the Terminal.
-
Verify that V works by running
v version
:
Hurrah! We now have V installed on our system. Let’s make a quick project and ensure everything works as expected.
A Test Run
Run v new hello_world
in an appropriate folder, like ~/v_projects
(or anywhere else you prefer). Enter whatever details you think are alright. Don’t worry too much about it, you can change it later by editing the v.mod
file.
Navigate into the folder and run v run
; you should be greeted with a classic hello world message!
Conclusion
And we’re done! You just set up a developer environment on macOS from scratch and ran some V code with it. In the next article, we will describe how to set up VS Code with the proper extensions and such.
If you run into any problems, feel free to reach out to us at [email protected] or our contact page.