Install xclip
$ sudo apt install xclip
Copy to clipboard
$ cat some_file.txt | xclip -selection clipboard
Paste to anywhere!
Showing posts with label Ubuntu 18.04 LTS. Show all posts
Showing posts with label Ubuntu 18.04 LTS. Show all posts
Saturday, May 4, 2019
Sunday, February 24, 2019
Resolving Bluetooth Issues with Ubuntu 18.04 LTS
So there are a few things that I do not like about Linux in general; quite a lot of things do not work automatically. One of the problems I have faced is that my Microsoft Designer mouse won't work with Ubuntu 18.04 LTS. After some research, I found this solution suggested by Newbuntie to work well, so I'm going to post this here for any other people going through the same trouble.
Basically, enter the following commands and you are good to go.
$ sudo add-apt-repository ppa:bluetooth/bluez
$ sudo apt install bluez
Enjoy!
Basically, enter the following commands and you are good to go.
$ sudo add-apt-repository ppa:bluetooth/bluez
$ sudo apt install bluez
Enjoy!
Friday, November 23, 2018
Learn Swift on Ubuntu: install and compile
Swift is a new language developed by Apple. Recently, I am studying Swift so that I can build iOS or macOS apps. In this post, I will go over how to setup Swift environment on Ubuntu 18.04 LTS.
First, install clang
$ sudo apt-get update && sudo apt-get install clang -y
Next, download Swift from Swift.org
$ wget https://swift.org/builds/swift-4.2.1-release/ubuntu1804/swift-4.2.1-RELEASE/swift-4.2.1-RELEASE-ubuntu18.04.tar.gz
Decompress
$ tar xfz swift-4.2.1-RELEASE-ubuntu18.04.tar.gz
Add swift binary directory to your PATH environment
$ export PATH=/path/to/swift/usr/bin:${PATH}
This is it for setting up the environment. Let's now build "hello world" in Swift.
Create hello.swift with the following content:
print("hello world")
To run your code, simply run
$ swift hello.swift
hello world
To compile and create a binary, run
$ swiftc hello.swift
./hello
hello world
That's it for this post. Happy hacking!
First, install clang
$ sudo apt-get update && sudo apt-get install clang -y
Next, download Swift from Swift.org
$ wget https://swift.org/builds/swift-4.2.1-release/ubuntu1804/swift-4.2.1-RELEASE/swift-4.2.1-RELEASE-ubuntu18.04.tar.gz
Decompress
$ tar xfz swift-4.2.1-RELEASE-ubuntu18.04.tar.gz
Add swift binary directory to your PATH environment
$ export PATH=/path/to/swift/usr/bin:${PATH}
This is it for setting up the environment. Let's now build "hello world" in Swift.
Create hello.swift with the following content:
print("hello world")
To run your code, simply run
$ swift hello.swift
hello world
To compile and create a binary, run
$ swiftc hello.swift
./hello
hello world
That's it for this post. Happy hacking!
Friday, October 26, 2018
Building Caffe2 and Pytorch for Ubuntu 18.04 LTS
I am trying to export my pytorch model to Android devices. It seems that using onnx and caffe2 is the easiest way to do so. Here, I will describe the steps to build and install pytorch & caffe2 for Ubuntu 18.04 LTS.
Basically, one has to follow the instructions here, but I had some problems building. The easiest way to build is to disable all unnecessary features. For example, since I am only going to port it to caffe2 and do not intend to use GPU for running pytorch model (at least for this python environment), I can set some flags:
$ export NO_CUDA=1
$ export NO_DISTRIBUTED=1
Also, I will build pytorch and caffe2 together. Hence, I set the flag
$ export FULL_CAFFE2=1
With these environment variables set, I successfully built and installed caffe2 and pytorch from the source, following the official instruction.
Happy hacking!
Basically, one has to follow the instructions here, but I had some problems building. The easiest way to build is to disable all unnecessary features. For example, since I am only going to port it to caffe2 and do not intend to use GPU for running pytorch model (at least for this python environment), I can set some flags:
$ export NO_CUDA=1
$ export NO_DISTRIBUTED=1
Also, I will build pytorch and caffe2 together. Hence, I set the flag
$ export FULL_CAFFE2=1
With these environment variables set, I successfully built and installed caffe2 and pytorch from the source, following the official instruction.
Happy hacking!
Wednesday, August 8, 2018
Enable S3 Sleep for Thinkpad X1 Carbon 6th Gen on Ubuntu
I recently purchased X1 C6; I am back to Thinkpad after 8 years of digression to Macbook. I will probably write a post explaining why I switched back, but for now I will focus on my story of getting S3 sleep with it under Ubuntu.
One thing I really miss from Macbook is how easy it was to simply close the lid and not worry about draining the battery. Unfortunately, with X1 C6, that is not the case. With Windows 10, closing the lid makes it go to Si03 sleep state where some processes can be on doing stuff in the background. The idea is great, but unfortunately in real world this new Si03 sleep state simply drains the battery so much that I just want to go back to old S3 state, where none of the processes can be on.
Since I installed Ubuntu on this machine and will mainly use Ubuntu, I searched for methods to enable S3 sleep rather than stupid Si03 sleep. After spending much time, I finally found a solution, and I want to share it with anyone who needs this.
At first, I tried this post, but did not work. Then, it was this answer here by Adonis that saved me. Basically, the missing step was to to generate grub.cfg file from grub-mkconfig from /etc/default/grub and then add initrd /boot/acpi_override.
Before this patch, it didn't even last a full day on sleep. Now with this patch, it seems to drain 10% a day in sleep. This is not as good as Macbook, which lasts about 30 days in sleep, so about 3% per day, but I guess this is better than 100% drain per day. With Windows, it was about 30% drain per day in sleep.
I really like this laptop, but I have to admit that I miss Macbook when it comes to this sort of minute convenience.
By the way, I really appreciate that people managed to create this patch and shared with all of us. I really respect their knowledge and skills. This was something Lenovo engineers could not even do!
One thing I really miss from Macbook is how easy it was to simply close the lid and not worry about draining the battery. Unfortunately, with X1 C6, that is not the case. With Windows 10, closing the lid makes it go to Si03 sleep state where some processes can be on doing stuff in the background. The idea is great, but unfortunately in real world this new Si03 sleep state simply drains the battery so much that I just want to go back to old S3 state, where none of the processes can be on.
Since I installed Ubuntu on this machine and will mainly use Ubuntu, I searched for methods to enable S3 sleep rather than stupid Si03 sleep. After spending much time, I finally found a solution, and I want to share it with anyone who needs this.
At first, I tried this post, but did not work. Then, it was this answer here by Adonis that saved me. Basically, the missing step was to to generate grub.cfg file from grub-mkconfig from /etc/default/grub and then add initrd /boot/acpi_override.
Before this patch, it didn't even last a full day on sleep. Now with this patch, it seems to drain 10% a day in sleep. This is not as good as Macbook, which lasts about 30 days in sleep, so about 3% per day, but I guess this is better than 100% drain per day. With Windows, it was about 30% drain per day in sleep.
I really like this laptop, but I have to admit that I miss Macbook when it comes to this sort of minute convenience.
By the way, I really appreciate that people managed to create this patch and shared with all of us. I really respect their knowledge and skills. This was something Lenovo engineers could not even do!
Thursday, June 21, 2018
How to Build Audacity on Ubuntu 18.04 LTS
Audacity is a great alternative to Adobe Audition. Here is how to build Audacity on Ubuntu 18.04 LTS, since there is no binary.
First, clone the git repo
$ git clone https://github.com/audacity/audacity.git
$ cd audacity
Next, install necessary packages:
$ sudo apt-get install -y libwxbase3.0-dev libwxgtk3.0-dev zlib1g-dev libasound2-dev libgtk-3-dev
Now, you are ready to configure and compile!
$ ./configure
$ make -j4
That's it!
First, clone the git repo
$ git clone https://github.com/audacity/audacity.git
$ cd audacity
Next, install necessary packages:
$ sudo apt-get install -y libwxbase3.0-dev libwxgtk3.0-dev zlib1g-dev libasound2-dev libgtk-3-dev
Now, you are ready to configure and compile!
$ ./configure
$ make -j4
That's it!
Monday, May 28, 2018
Import CMAKE Project on NetBeans
In the previous post, I discussed how to import a CMAKE project for Eclipse, and it wasn't that easy. Today, I will discuss how to import a CMAKE project on NetBeans. Again, I will use cmake-exmaple as an example project.
Clone and download the CMAKE project on your computer.
$ git clone https://github.com/bast/cmake-example.git ~/cmake-example
First, open up NetBeans C++ IDE. If you are running it on Mac OS X, I recommend running it from Terminal
$ /Applications/NetBeans/NetBeans\ 8.2.app/Contents/MacOS/netbeans
The reason is that if you simply run NetBeans from GUI, your environment variables might not sync.
Next, select File --> New Project --> C/C++ Project with Existing Sources --> Next. Choose Browse the folder which contains your CMAKE project, in this example ~/cmake-example folder. Select Custom under Select Configuration Mode and select Next. Check-box Pre-Build Step is Required. Specify Run in Folder as the project root directory, i.e., ~/cmake-example. Enter the following for Command
cmake -H. -Bbuild
Continue with remaining options and adjust what is necessary. Usually, the default setting should work.
Once the project has been imported, you will need to verify the settings. Right-click the project name cmake-example on the project pane on the left, and select Properties. Make sure in the Build --> Pre-Build option, you have the Command Line is set as cmake -H. -Bbuild and Pre-Build First box is checked.
In the Build --> Make option, the Working Directory should be set as build, since this is where the build will take place. Select Apply and Close.
Press <F11> key to build the project. It should build successfully. Before we debug this, we have to make sure to set debug flag in the CMakeLists.txt file by setting CMAKE_CXX_FLAGS.
Open up CMakeLists.txt file in the project root directory, that is ~/cmake-example/CMakeLists.txt and not the file in the src directory. Modify line 35 to look as below:
# project version
set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_PATCH 0)
set(CMAKE_CXX_FLAGS '-g')
Now, we are ready to run or debug. Re-build the project, and set breakpoint on src/main.cpp file. You should be able to debug it successfully.
Happy coding!
Clone and download the CMAKE project on your computer.
$ git clone https://github.com/bast/cmake-example.git ~/cmake-example
First, open up NetBeans C++ IDE. If you are running it on Mac OS X, I recommend running it from Terminal
$ /Applications/NetBeans/NetBeans\ 8.2.app/Contents/MacOS/netbeans
The reason is that if you simply run NetBeans from GUI, your environment variables might not sync.
Next, select File --> New Project --> C/C++ Project with Existing Sources --> Next. Choose Browse the folder which contains your CMAKE project, in this example ~/cmake-example folder. Select Custom under Select Configuration Mode and select Next. Check-box Pre-Build Step is Required. Specify Run in Folder as the project root directory, i.e., ~/cmake-example. Enter the following for Command
cmake -H. -Bbuild
Continue with remaining options and adjust what is necessary. Usually, the default setting should work.
Once the project has been imported, you will need to verify the settings. Right-click the project name cmake-example on the project pane on the left, and select Properties. Make sure in the Build --> Pre-Build option, you have the Command Line is set as cmake -H. -Bbuild and Pre-Build First box is checked.
In the Build --> Make option, the Working Directory should be set as build, since this is where the build will take place. Select Apply and Close.
Press <F11> key to build the project. It should build successfully. Before we debug this, we have to make sure to set debug flag in the CMakeLists.txt file by setting CMAKE_CXX_FLAGS.
Open up CMakeLists.txt file in the project root directory, that is ~/cmake-example/CMakeLists.txt and not the file in the src directory. Modify line 35 to look as below:
# project version
set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_PATCH 0)
set(CMAKE_CXX_FLAGS '-g')
Now, we are ready to run or debug. Re-build the project, and set breakpoint on src/main.cpp file. You should be able to debug it successfully.
Happy coding!
Tuesday, May 22, 2018
Import CMAKE Project to Eclipse CDT
In this post, I will discuss how to import a CMAKE project to Eclipse CDT. Upon Google search, I ran into this solution, but this did not work for me, so here is what I did instead. I am going to make use of cmake-example git repo project to demonstrate how, but you can easily do this for your own.
Open up Eclipse CDT and select File --> New --> C/C++ Project --> C++ Managed Build --> Next. Enter the project name, say cmake-example, and make sure the project type is Empty Project. Also, select the appropriate Toolchains; this will be Linux GCC or MacOSX GCC. Select Finish.
Go to the project root folder, and we will clone the git repository.
$ cd ~/Eclipse/workspace/cmake-example
$ git init
$ git remote add origin https://github.com/bast/cmake-example.git
$ git fetch
$ git checkout -t origin/master
Let's verify that the project compiles.
$ cmake -H. -BDebug
$ cd Debug
$ make -j4
Make sure that the project builds successfully. Also, note down your $PATH environment variable (highlighted in blue below) to be used later. Your variable may differ from mine.
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
Now, on Eclipse right-click this project in the Project Explorer pane on the left and select Properties. In the C/C++ Build tab, uncheck both Use default build command and Generate Makefile automatically. Make sure the Build Directory as ${workspace_loc:/cmake-example}/Debug. This is the folder we created with CMAKE in the previous step and built the project. This folder contains CMAKE-generated Makefile, and we are simply asking Eclipse to execute make command in this particular folder.
This is the first step, where the Eclipse simply runs the make command of the Makefile generated from CMAKE. This setup is good if we are not going to edit CMAKE configs anymore. In reality, we probably will need to edit CMAKE configs.
Every time you modify CMakeLists.txt, you will need to re-create Makefile by running the CMAKE command again and again
$ cmake ..
Let's simply automate this build command with Eclipse. This is the second step of this post. Create build.sh in the project folder,
$ vim ~/Eclipse/workspace/cmake-example/build.sh
Simply write down the build commands that you would run from the Debug directory as follows:
cmake ..
make -j4
Now, in the Eclipse open up Project Properties window again. Expand C/C++ Build entry on the left and select Environment. Select Add button, and enter PATH for the Name field and your $PATH environment variable (noted in the previous step) for the Variable field. This is to make sure the Eclipse shell will be able to perform exactly what you can do with your own shell.
In the C/C++ Build tab, enter the following build command in place of make
sh ../build.sh
Select Apply and Close to close the properties window. The project should now successfully build, even if you have modified CMakeLists.txt files.
Lastly, you can modify the run command by selecting Run --> Run Configurations... and browse the executable for C/C++ Application:
~/Eclipse/workspace/cmake-example/Debug/bin/unit_tests
Happy hacking!
Open up Eclipse CDT and select File --> New --> C/C++ Project --> C++ Managed Build --> Next. Enter the project name, say cmake-example, and make sure the project type is Empty Project. Also, select the appropriate Toolchains; this will be Linux GCC or MacOSX GCC. Select Finish.
Go to the project root folder, and we will clone the git repository.
$ cd ~/Eclipse/workspace/cmake-example
$ git init
$ git remote add origin https://github.com/bast/cmake-example.git
$ git fetch
$ git checkout -t origin/master
Let's verify that the project compiles.
$ cmake -H. -BDebug
$ cd Debug
$ make -j4
Make sure that the project builds successfully. Also, note down your $PATH environment variable (highlighted in blue below) to be used later. Your variable may differ from mine.
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
Now, on Eclipse right-click this project in the Project Explorer pane on the left and select Properties. In the C/C++ Build tab, uncheck both Use default build command and Generate Makefile automatically. Make sure the Build Directory as ${workspace_loc:/cmake-example}/Debug. This is the folder we created with CMAKE in the previous step and built the project. This folder contains CMAKE-generated Makefile, and we are simply asking Eclipse to execute make command in this particular folder.
This is the first step, where the Eclipse simply runs the make command of the Makefile generated from CMAKE. This setup is good if we are not going to edit CMAKE configs anymore. In reality, we probably will need to edit CMAKE configs.
Every time you modify CMakeLists.txt, you will need to re-create Makefile by running the CMAKE command again and again
$ cmake ..
Let's simply automate this build command with Eclipse. This is the second step of this post. Create build.sh in the project folder,
$ vim ~/Eclipse/workspace/cmake-example/build.sh
Simply write down the build commands that you would run from the Debug directory as follows:
cmake ..
make -j4
Now, in the Eclipse open up Project Properties window again. Expand C/C++ Build entry on the left and select Environment. Select Add button, and enter PATH for the Name field and your $PATH environment variable (noted in the previous step) for the Variable field. This is to make sure the Eclipse shell will be able to perform exactly what you can do with your own shell.
In the C/C++ Build tab, enter the following build command in place of make
sh ../build.sh
Select Apply and Close to close the properties window. The project should now successfully build, even if you have modified CMakeLists.txt files.
Lastly, you can modify the run command by selecting Run --> Run Configurations... and browse the executable for C/C++ Application:
~/Eclipse/workspace/cmake-example/Debug/bin/unit_tests
Happy hacking!
Install Ubuntu without a USB Stick
Disclaimer: I recommend that you experiment the method written in this post on a virtual machine first, because it can get quite tricky.
Let's say you want to wipe out your entire system and install Ubuntu. The easiest way is perhaps
1. download Ubuntu Live Image,
2. create a bootable USB stick, and
3. boot from the USB.
Well, if you were like me, who wipe out the entire system often, you will find it quite annoying to locate the USB, create the bootable stick, and so on. Furthermore, what if you don't have a USB stick in possession?
This post is to rescue you in such situations. You can simply download the image and boot from the image stored on your disk! Let's see how we can do this. Some of the references are here and here.
Here is the setup. First, you will need at least two partitions on your disk. One is Linux installation partition, and the other is to hold the iso image. Throughout the post, I am going to assume that your first partition is mounted as / and your second partition is mounted as /data.
You will need to download the Ubuntu Live image to the second partition, say
$ wget http://releases.ubuntu.com/18.04/ubuntu-18.04-desktop-amd64.iso -P /data
Now, you will have the iso image file saved as /data/ubuntu-18.04-desktop-amd64.iso. Make sure that you save the image in the partition other than where the Linux will be installed.
Next, you need to add a grub menu entry.
$ sudo vim /etc/grub.d/40_custom
Your file should look like below:
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry "Ubuntu 18.04 LTS" {
set isofile="/ubuntu-18.04-desktop-amd64.iso"
loopback loop (hd0,2)$isofile
echo "Starting $isofile..."
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=${isofile} quiet splash
initrd (loop)/casper/initrd.lz
}
Let me go over the system partition scheme once more. The above file applies to the partition scheme where
partition 1: /dev/sda1 --> currently mounted as /; will install Linux on this partition
partition 2: /dev/sda2 --> currently mounted as /data; holds the iso image
Since you downloaded the iso image on the /data directory, this is the root of the second partition. Therefore, this is specified as (hd0,2) in the grub menu entry, corresponding to /dev/sda2; we must omit /data here because /data is just the mount-point in currently-running system and grub won't know anything about it. If you have different partition scheme from mine, you will need to edit the entry accordingly.
Finally, you will need to update grub
$ sudo update-grub
Let's reboot the system and see if we can indeed boot from the iso from the current disk.
$ sudo reboot
Make sure to press and hold <Shift> key while booting up, so that grub entry appears. Otherwise, it is likely that grub menu entry won't even appear.
If you have correctly followed till now, you should be able to boot from the iso image. You should even be able to install Ubuntu on partition 1 using the iso image saved in partition 2. However, you will notice that during the installation, it complains that /isodevice cannot be unmounted. You can resolve this issue by running the following in the terminal within the Live Image system (not your currently installed system):
$ sudo umount -l -r -f /isodevice
After running this command, you should be able to successfully wipe out partition 1 and install Ubuntu 18.04 fresh!
Let's say you want to wipe out your entire system and install Ubuntu. The easiest way is perhaps
1. download Ubuntu Live Image,
2. create a bootable USB stick, and
3. boot from the USB.
Well, if you were like me, who wipe out the entire system often, you will find it quite annoying to locate the USB, create the bootable stick, and so on. Furthermore, what if you don't have a USB stick in possession?
This post is to rescue you in such situations. You can simply download the image and boot from the image stored on your disk! Let's see how we can do this. Some of the references are here and here.
Here is the setup. First, you will need at least two partitions on your disk. One is Linux installation partition, and the other is to hold the iso image. Throughout the post, I am going to assume that your first partition is mounted as / and your second partition is mounted as /data.
You will need to download the Ubuntu Live image to the second partition, say
$ wget http://releases.ubuntu.com/18.04/ubuntu-18.04-desktop-amd64.iso -P /data
Now, you will have the iso image file saved as /data/ubuntu-18.04-desktop-amd64.iso. Make sure that you save the image in the partition other than where the Linux will be installed.
Next, you need to add a grub menu entry.
$ sudo vim /etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry "Ubuntu 18.04 LTS" {
set isofile="/ubuntu-18.04-desktop-amd64.iso"
loopback loop (hd0,2)$isofile
echo "Starting $isofile..."
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=${isofile} quiet splash
initrd (loop)/casper/initrd.lz
}
Let me go over the system partition scheme once more. The above file applies to the partition scheme where
partition 1: /dev/sda1 --> currently mounted as /; will install Linux on this partition
partition 2: /dev/sda2 --> currently mounted as /data; holds the iso image
Since you downloaded the iso image on the /data directory, this is the root of the second partition. Therefore, this is specified as (hd0,2) in the grub menu entry, corresponding to /dev/sda2; we must omit /data here because /data is just the mount-point in currently-running system and grub won't know anything about it. If you have different partition scheme from mine, you will need to edit the entry accordingly.
Finally, you will need to update grub
$ sudo update-grub
Let's reboot the system and see if we can indeed boot from the iso from the current disk.
$ sudo reboot
Make sure to press and hold <Shift> key while booting up, so that grub entry appears. Otherwise, it is likely that grub menu entry won't even appear.
If you have correctly followed till now, you should be able to boot from the iso image. You should even be able to install Ubuntu on partition 1 using the iso image saved in partition 2. However, you will notice that during the installation, it complains that /isodevice cannot be unmounted. You can resolve this issue by running the following in the terminal within the Live Image system (not your currently installed system):
$ sudo umount -l -r -f /isodevice
After running this command, you should be able to successfully wipe out partition 1 and install Ubuntu 18.04 fresh!
Subscribe to:
Posts (Atom)