How to Setup Kvaser on Linux [Ubuntu]

Tested Device:

Kvaser Leaf Light v2 HS USB to CAN Bus Interface


Method 1: Set up to use CANLIB (library from Kvaser, if you want to use socketcan, skip to method 2)

  1. The download page for all necessary files can be accessed here:
  2. Install drivers according to this tutorial after download the Kvaser LINUX Driver and SDK file. I tested it on Ubuntu 16.04, and it’s still working.

3. To use Kvaser with Python, you need canlib library. To install canlib for python on linux, follow the instruction here after download the latest Python Module from the Download page.

4. More detail on canlib codes:

Method 2: Setup to use with Socketcan

This method is a lot more simple, there is no need for any driver set up. 

  1. Install can-ultils (for socketcan): sudo apt-get install can-utils
  2. Connect Kvaser to PC
  3. Enable CAN, in this example, I use 500000. Change this bitrate to your required speed:
    sudo modprobe can
    sudo modprobe can_raw
    sudo ip link set can0 type can bitrate 5000000
    sudo ip link set up can0
  4. Your Kvaser can port is enable with name can0, run ifconfig -a and can0 should show up. Connect Kvaser to another CAN device that is sending out data, then on terminal enter candump can0
    Note: After PC restarts, you will have to re-run these commands if you want to enable Socketcan for Kvaser device again. To save time, you can save these in a bash script and load from the bash script. 
  5. To use Socketcan in Python codes, check out Python-can

Refer to the resource below to use can-ultils on termial to test send and receive can messages on terminal. If you don’t have another CAN device to test send and receive, you can also create virtual can channel to do the work.


    1. If mhydra is CAN hardware, you need to verify Ubuntu installs the drivers from them or you have to build and install the drivers manually.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s