Learn how to install an Open edX XBlock code extension with this detailed step-by-step how-to guide. This step-by-step guide works for any XBlock. Let’s get started!
XBlock is the extensibility framework for Open edX. That is, it’s a framework that allows the open source software development community to extend and enhance edX to meet future needs. If you’re familiar with the content management system WordPress then, architecturally speaking, XBlocks are nearly identical to plugins. ExtensionEngine wrote this great blog article on XBlocks. However, a big difference between WordPress plugins and XBlocks is that installing them is a murky process. In this blog post I set out clarify and simplify the exact steps that are required to install any XBlock.
For this tutorial we’ll install a really cool XBlock named In-Video Quiz which, as the name implies, will abruptly pause a video to present the student with a problem. This XBlock was written by the Open edX programming team at Stanford University and is freely available on GitHub (https://github.com/Stanford-Online/xblock-in-video-quiz). Like many XBlocks that I’ve installed, the functionality works great, but the documentation is sparse. So, the In-Video Quiz is a great example for this blog post.
Before moving on I’ll point out a couple of things that might weigh on your installation choices. First, you can install XCode packages anywhere in your Ubuntu server. References to the code are bound during the automated installation process. But having said that, I would recommend that you NOT install XCode packages anywhere inside of the /edx subdirectory simply because doing this can complicate future platform software upgrades. That is, if you install you XBlock packages anywhere inside the /edx subdirectory, it might get overwritten during a future upgrade of any part of the Open edX platform.
- Your Open edX instance is running from an AWS account
- Your AWS EC2 instance is running on an Ubuntu 16.04 LTS server built from the Amazon Linux AMI
- You have SSH access to your EC2 instance and sudo capability
- You are generally familiar with GitHub packages (you’ve at least heard of them)
- Your Open edX instance is substantially based on the guidelines published here: Native Open edX Ubuntu 16.04 64 bit Installation
1. Clone The GitHub Repository of the XBlock Package
Like Open edX itself, XBlocks are written in Python, and while I’m not a Python programmer myself, I will say that I’ve observed that the Python programming community tends to have a preferred way to do everything; and that includes for example, how Python programs should be installed. That being the case, a lot of Python programs (or all of them?) are stored as raw source code which one downloads in packages from repository platforms like GitHub to be compiled on the server using a variety of Python-specific installations tools. In the case of Open edX the preferred route seems to be a command line utility named pip (Python Installation Program). I’m a Python neophyte, just so you know. But regardless, pip is pretty awesome, and pretty stupid-proof.
All of this matters because XBlocks are written in Python and, as it happens, thanks in no small measure to the peculiarities of the Python community, there’s one single method of installation that works for all XBlocks. First, we need to clone the GitHub repository where our In-Video Quiz is stored. I can almost always find the GitHub repository by using Google. Once you find the repository, GitHub provides a 1-click way to copy the exact http URI of the repository, which we’ll use on the command line of our Ubuntu instance. Refer to the following screen shot for the location of the 1-click copy method:
Afterwards, paste the URI of the repository onto the command line so that you have a command line that looks like the following:
$ cd ~ $ git clone https://github.com/Stanford-Online/xblock-in-video-quiz.git
2. Change Ownership of the Repository directory in Ubuntu
Cloning the GitHub repository simply means copying all of the files (and whatever else might be in the repository like say, images, mp3s, etc) to your Ubuntu file system.
I clone repositories into the Ubuntu home folder /home/ubuntu/ where I also store any and all other Open edX configuration files and scripts. However, feel free to clone the repository to whatever location in your file system you prefer as this (within reason) has no bearing on the installation process.
Once you’ve cloned the repository you’ll also need to change the folder ownership and group to edxapp. This is because we’ll install the code using the edxapp user, and if the source code itself doesn’t reside in a folder that’s owned by this user then the pip installation program will potentially complain.
$ sudo chown -R edxapp xblock-in-video-quiz
$ sudo chgrp -R edxapp xblock-in-video-quiz
3. Run the pip Installation Program
This is where the magic happens. We’re going to use pip (Python Installation Program) to install our XBlock. Python programmers are a thorough bunch. They not only think about their code’s functionality, but also the code dependencies of their code, and even the version compatibility. Ultimately, pip does all of this for us. Therefore, the specifics on how to run pip might seem underwhelming, but here it is:
unrecognized requirement ... is XXX a path?, then consider changing the local installation location of your Xblock files.
# To install the xblock: sudo -H -u edxapp bash source /edx/app/edxapp/edxapp_env /edx/bin/pip.edxapp install /home/ubuntu/xblock-in-video-quiz # To uninstall the xblock (in the event of problems): /edx/bin/pip.edxapp list #then look for the registered name of the Xblock. #In this example the Xblock name is, "invideo-quiz (0.x.x)" /edx/bin/pip.edxapp uninstall THE-REGISTERED-NAME-OF-THE-XBLOCK-TO-UNINSTALL
We now find ourselves in one of those, “the proof is left to the reader” moments. :/