Virtualenv: workon command not found - linux

I have installed virtualenv and the virtualwrapper via apt-get, I got to a point where I created a virtual enviroment but however later on during that same day when I used the workon command it was not found. I further on went and inspected my home directory and .virtualenvs dir and the virtualenv I created earlier were still there.

Solving this problem took two steps:
Add this to your .bashrc / .bash_profile / .zshrc:
# load virtualenvwrapper for python (after custom PATHs)
venvwrap="virtualenvwrapper.sh"
/usr/bin/which -s $venvwrap
if [ $? -eq 0 ]; then
venvwrap=`/usr/bin/which $venvwrap`
source $venvwrap
fi
Then use:
source .bash_profile
# or .bashrc / .zshrc
to reflect the changes.
Additionally, if the terminal still sometimes cant find workon, use source .bash_profile to reset and find it again.

type source .profile in home directory from terminal.

Read the readme in the top of which virtualenvwrapper.sh
You need to source it inside bashrc

open ~/.profile
cd ~
nano .profile
add at the end
#virtualenvwrapper setup
export WORKON_HOME=$HOME/envs
export PROJECT_HOME=$HOME/dev
source /usr/local/bin/virtualenvwrapper.sh
to load your .profile file you just edited:
$ . .profile

I ran in to this problem too and I simply needed to logout and log back in.
This read in the changes which the debian package manager made to my system at /etc/bash_completion.d/virtualenvwrapper

Related

Issues setting $PATH on Bash on Ubuntu on Windows (Linux Subsystem)

I am using the "Bash on Ubuntu on Windows" (Linux Subsystem) and want to add Terraform to my $PATH. Since Terraform can't be installed via apt-get, I did the following steps:
Navigated to this directory, where I wanted to install Terraform:
cd /usr/local
In the above path, I used wget to download Terraform:
wget
https://releases.hashicorp.com/terraform/0.9.8/terraform_0.9.8_linux_amd64.zip
Terraform successfully unzips! When I open the file in VIM it is all good:
unzip terraform_0.9.8_linux_amd64.zip
I then enter this command to check to see if the Terraform binary is accessible from the command line:
terraform -version
However the following message gets returned:
terraform: command not found
This tells me that the Terraform downloaded location needs to be added to my $PATH.
Already being logged in as the root user ("sudo su") I enter the following command to access ".profile":
vim ~/.profile
The following is already in this file, which I leave untouched:
# ~/.profile: executed by Bourne-compatible login shells.
if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi
mesg n
Immediately below this text, I add the following, and successfully save the file using :wq!:
export PATH=/usr/local/bin:$PATH
export PATH=$PATH:/usr/local/terraform
6.
I then again enter the following command to check to see if terraform is detected
terraform -version
Still the same "terraform: command not found" message is returned. I even tried closing out and starting a new command line session and even restarting my computer. Still no change.
Anyone have any ideas on how to resolve this? Again, note that I am using "Bash on Ubuntu on Windows" (Linux Subsystem). Any input would be appreciated!
The direct answer to your problem is at the end.
But I think it will make more sense if you keep reading from here.
Before trying to add to PATH,
I recommend to test a program first.
In your case I would do like this:
wget https://releases.hashicorp.com/terraform/0.9.8/terraform_0.9.8_linux_amd64.zip
unzip terraform_0.9.8_linux_amd64.zip
./terraform
Notice the last line ./terraform.
The zip file contains a single file, terraform,
which now should be in the current directory,
so I can run it with ./terraform.
If it's executable.
If it's not executable then confirm it:
ls -l terraform
And make it executable if needed:
chmod +x terraform
Now let's add it to PATH.
But first,
let's decide where to put this executable.
/usr/local/bin seems a reasonable location.
So let's move the terraform executable into that directory.
Usually /usr/local/bin is already on PATH,
so you might not need to change anything.
Now you can try your check, and there's a good chance it already works:
terraform -version
If it doesn't, then /usr/local/bin is not on the PATH.
To add it, add this line in ~/.profile:
export PATH=$PATH:/usr/local/bin
Two things looked fundamentally wrong with your approach:
Adding /usr/local/terraform to PATH. This is fishy, because the entries on PATH must be directories, and in your post nothing indicates that you created a directory at /usr/local/terraform.
You cd into /usr/local, and then unzip the zip file of terraform. The linked zip contains a single file named terraform, so /usr/local/terraform in your example should be a file.
If it is a file, then you could make it executable as terraform by adding to add to PATH its base directory. But adding /usr/local to PATH would not be a good idea. It's conventional to put binaries into /usr/local/bin, not directly into /usr/local
You did not mention how you reloaded ~/.profile. After editing this file, the new commands you added do not get automatically executed in your current shell. They will get executed when you open a new shell. Or you could manually execute the added commands in the current shell.
Hit below command
export PATH=$PATH:/usr/local/bin

Anaconda fedora install: conda: command not found

I've installed Anaconda and have added the environment variable export PATH="~/anaconda/bin:$PATH" to my .zshrc but still can't run any 'conda' commands in my terminal. I have followed these commands(source) to install anaconda.
# Go to home directory
cd ~
# You can change what anaconda version you want at
# https://repo.continuum.io/archive/
wget https://repo.continuum.io/archive/Anaconda3-4.2.0-Linux-x86_64.sh
zsh Anaconda3-4.2.0-Linux-x86_64.sh -b -p ~/anaconda
rm Anaconda3-4.2.0-Linux-x86_64.sh
echo 'export PATH="~/anaconda/bin:$PATH"' >> ~/.zshrc
# Refresh basically
source ~/.zshrc
Am I missing anything?
This kind of issue often arise due to incorrect paths to your Python distribution. Basically, your computer does not know where to look for the correct file or program and you need to tell it where to look using your system's $PATH variable. You will thus need to manually set the paths by editing your .profile or .rc file. The most commonly used shell is bash. Both Anaconda and Canopy assume you're running the Bash shell and will put the path to your install there.
The steps below worked for me on Mac, it should work on Linux as well:
1. Go to your home directory by typing cd ~ from the prompt, or by open that same directory in Finder.
2. Now get a list of all the files in this folder, including the hidden ones:
ls -la
or, directly in Finder (without the "+"):
CMD + SHIFT + .
Now, you probably have (a) both the .profile and .bash_profile, or (b) just one of them, or (c) none of them:
3.a If you are using Bash, you're looking for files called .profile and .bash_profile. Which you have will depend on your system configuration. If you have both, this is probably the root cause of your problem; .bash_profile overrides .profile if both are present. In this case, open .profile and copy everything you find inside across to .bash_profile.
3.b If you only have one of .bash_profile or .profile, open it in an editor and have a look. You're looking for any obvious references to Python or your distribution (Anaconda, Canopy) on any of the uncommented-out lines. You'll probably see several lines that look something like:
PATH="Users/<your user name>/Library/...:${PATH}"
export PATH
In the rare case that you don't see any reference to Anaconda at all, you will need to add the lines yourself. Add, for example, the following to the file:
export PATH=~/anaconda/bin:$PATH
3.c If it turns out that you don't have any of the files, you would have to create one by yourself. Do this by entering touch .bash_profile in the prompt, or, simply right click and create a new file directly in Finder. Add the following to the file (same as in (b)):
export PATH=~/anaconda/bin:$PATH
4. Save the file. Quit and restart any program that use Python (including the Terminal window), and you should be good to go.
More detailed info here (including for Windows):
https://github.com/landlab/landlab/wiki/Correcting-Install-Paths

Issue with ~/.profile after fixing NPM permissions

Installed Node.js on OS X. Fixed the permissions (i.e. sudo required) issue by changing NPM's default directory (https://docs.npmjs.com/getting-started/fixing-npm-permissions see Option 2). However, after booting up commands like grunt are not available until I run source ~/.profile.
Any way to avoid this hassle?
Did the node/NPM setup create a ~/.bash_profile or ~/.bash_login file? if so, bash will source that instead of ~/.profile at startup. If this is the problem, there are a couple of ways to fix it:
Copy the contents of your ~/.profile file into ~/.bash_profile (or ~/.bash_login). You may also want to delete ~/.profile to avoid future confusion.
Add a command to ~/.bash_profile (or ~/.bash_login) to source ~/.profile as well:
[ -f ~/.profile ] && source ~/.profile

How do I SET the GOPATH environment variable on Ubuntu? What file must I edit?

I am trying to do a go get:
go get github.com/go-sql-driver/mysql
and it fails with the following error:
package github.com/go-sql-driver/mysql: cannot download, $GOPATH not set. For more details see: go help gopath
when I do a go env , a list of Go values is shown as below:
ubuntu#ip-xxx-x-xx-x:~$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CGO_ENABLED="1"
clearly the GOPATH is not set, how and where do I set it?
I see many threads that mention this error but none that provide an answer to my question, which file needs to be edited to provide a value for this path?
New Way:
Check out this answer.
Note: Not for trying out a go application / binaries on your host machine using go install [repo url], in such cases you still have to use the old way.
Old Way:
Just add the following lines to ~/.bashrc and this will persist. However, you can use other paths you like as GOPATH instead of $HOME/go in my sample.
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
New Way: Go Modules
Since Go 1.11, you don't have to use GOPATH anymore. Simply go to your project directory and do this once:
go mod init github.com/youruser/yourrepo
With this, Go creates a module root at that directory.
You can create as many modules as you want.
For step by step instructions, also see this answer.
Old Way: GOPATH
If you insist on working with GOPATH then heed this:
Since Go 1.8, you don't need to set your GOPATH or GOROOT.
GOPATH by default is under your user/home directory.
From the documentation:
If no GOPATH is set, it is assumed to be $HOME/go on Unix systems and %USERPROFILE%\go on Windows. If you want to use a custom location as your workspace, you can set the GOPATH environment variable.
Ubuntu 14.04
export GOPATH=$HOME/go
Additionally you can add this string to file
$HOME/.bashrc
GOPATH should be set to a newly created empty directory. This is the go "workspace", where it downloads packages, et cetera. I use ~/.go.
For example:
mkdir ~/.go
echo "GOPATH=$HOME/.go" >> ~/.bashrc
echo "export GOPATH" >> ~/.bashrc
echo "PATH=\$PATH:\$GOPATH/bin # Add GOPATH/bin to PATH for scripting" >> ~/.bashrc
source ~/.bashrc
source: http://www.larry-price.com/blog/2013/12/15/setting-up-a-go-environment-in-ubuntu-12-dot-04/
If for example, it is an Ubuntu, after installing the packages:
$sudo apt install golang -y
Just add the following lines to ~/.bashrc (Of your user)
export GOROOT=/usr/lib/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
export GOPATH=/path/desired/here
There is no need to edit any file, we can just use the command above to directly edit the Go environment variables.
Write this code in Terminal.
export GOPATH=path/to/your/gopath/directory
Note: This will reset on every new Terminal window or system restart.
To be persistent, paste the code below in your .zshrc or .bashrc file according to your shell. Those files in your Home Directory. It will be like below.
export PATH=path/to/some/other/place/composer/for/example
export GOPATH=path/to/your/gopath/directory
export PATH=$PATH:$GOPATH/bin
For Go 1.13+:
go env -w GOPATH=$HOME/go
To set the GOPATH regardless of the GO version add the following line to your ~/.bashrc:
export GOPATH=$HOME/go
and don't forget to source your .bashrc file:
source ~/.bashrc
More options on the golang official wiki:
https://github.com/golang/go/wiki/SettingGOPATH
You will need GOPATH later, too. So add it to ~/.bashrc.
If you've setup anything that needs modification of environment variables e.g. Java, Go etc this will be very familiar.
I will assume that you have the following directory structure somewhere as your Go path:
\---[folder name]
+---bin
+---pkg
\---src
open a new terminal
type sudo nano /etc/environment
find PATH=... and go the end of it and add a colon : after the last path then paste in your full go path e.g. /home/user/gocode
and you're done, This should make it persistent through the system.
export GOROOT=/usr/lib/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin
And you may want to check by
$ go env
Just add the following lines to ~/.bashrc
export GOROOT=/usr/lib/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
This is what got it working for me on Ubuntu 15.10 using the fish shell:
# ~/.config/fish/config.fish
set -g -x PATH /usr/local/bin $PATH
set -g -x GOPATH /usr/share/go
Then I had to change the permissions on the go folder (it was set to root)
sudo chown <name>:<name> -R /usr/share/go
go path could be every where you want just create a directory and set global path variable in the name of GOPATH to your environment.
mkdir ~/go
export GOPATH=~/go
go get github.com/go-sql-driver/mysql
GOPATH is an environment variable to your work-space location.
GOROOT is an environment variable to your installation directory. Although GOROOT and GOPATH is automatically set (if there would not be a bug) during the installation time, to specify it manually you can follow below process. Moreover, for more information you can refer to GO's wiki page.
It is better to set GOPATH to a directory inside your home directory, e.g., $HOME/go, %USERPROFILE%\go (Windows).
This is a solution mac, which is tested on macOS Sierra, ver. 10.12, and also in Gogland-EAP, which has been introduced as an IDE for Go programming by JetBrains.
On your Terminal type
vim ~/.profile
in opened document on the Terminal press i and add the following path
GOPATH=/path/to/a/directory/inside/home/directory
GOROOT=/path/to/you/go/library
PATH=$PATH:$GOPATH:$GOROOT:$GOROOT/bin
press ESC and type :x.
Lastly, you should restart (close and open) your terminal or Logout and Login again.
For Windows and Linux configuration, please refer to Go wiki page at Githab on Setting GOPATH-Golang.
CAUTION Do not set both GOROOT and GOPATH to the same directory, otherwise you will get a warning.
(Ubuntu)
If you don’t set a GOPATH, the default will be used.
You have to add $GOPATH/bin to your PATH to execute any binary installed in $GOPATH/bin, or you need to type $GOPATH/bin/the-command.
Add this to your ~/.bash_profile
export PATH=$GOPATH/bin:$PATH
Current GOPATH command:
go env GOPATH
Changing the GOPATH command:
export GOPATH=$HOME/your-desired-path
With Go 1.8 (Q2 2017), you won't have to edit any file if you accept the default GOPATH value (set for you)
$HOME/go
You can see the comments on issue 17262 and the associated twitter vote:
By choosing a default GOPATH, we can make our documentation easier because we can say things like
$ go get github.com/foo/bar
will check out the github.com/foo/bar repo into $HOME/go/src/github.com/foo/bar.
We don't need to distract newcomers with having to set an env var, all we need to do is put a little parenthetical note at the bottom of the page
$HOME/go is the default path to your go workspace.
If you want to change this path, set the GOPATH variable to something of your choosing.
My go environment looked similar to yours.
$go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/lib/go-1.6"
GOTOOLDIR="/usr/lib/go-1.6/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
I resolved it with setting GOPATH to /usr/lib/go. Try it out.
export GOPATH=/usr/lib/go
export PATH=$PATH:$GOPATH/bin
At the end of the ~.profile file add::
export GOPATH="$HOME/go"
export PATH="$PATH:/usr/local/go/bin"
export PATH="$PATH:$GOPATH/bin"
if you are using zsh :
nano ~/.zshrc
then add to the end of the file :
export PATH=$PATH:/usr/local/go/bin
finally :
source ~/.zshrc
and open a new terminal
go version
export PATH=$PATH:$(go env GOPATH)/bin
This has been the most annoying thing to deal with. In hopes of saving your time.
IF go was installed as root user. The root user of your system's bash_profile text file ~/.bash_profile needs to have $GOROOT assigned to the go install directory and $GOPATH needs to be assigned to go /src directory.
...$# sudo su
...$# vi ~/.bash_profile
***Story continues in vi editor***
GOROOT=$GOROOT:/usr/local/go
GOPATH=$GOPATH:/usr/local/go/src
...
[your regular PATH stuff here]
...
be sure the path to go binary is in your path on .bash_profile
PATH=$PATH:$HOME/bin:/usr/local/bin:/usr/local/go/bin
This PATH can be as long a string it needs to be..to add new items just separate by colon :
exit vi editor and saving bash profile (:wq stands for write and quit)
[esc]
[shift] + [:]
:wq
You have to log out of terminal and log back in for profile to initiate again..or you can just kick start it by using export.
...$# export GOPATH=/usr/local/go/src
You can verify go env:
...$# go env
Yay!
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/local/go/src"
GORACE=""
GOROOT="/usr/local/go"
Now you can sudo and go will be able to download and create directories inside go/src and you can get down to what you were trying to get done.
example
# sudo go get github.com/..
Now you will run into another problem..you might not have git installed..that's another adventure..:)
On my Fedora 20 machine I added the following lines to my ~/.bashrc:
export GOROOT=/usr/lib/golang
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Yet another solution: Export every GO* environment variable from go env
.bashrc:
eval $(go env | grep '^GO[A-Z0-9_]*=' | while read setenv; do
echo "export $setenv; "
done 2> /dev/null)
[[ -n $GOPATH ]] || export GOPATH="$HOME/go/bin"
[[ -n $GOROOT ]] || export GOROOT=/usr/bin/go
export PATH="$PATH:$GOPATH/bin:$GOROOT/bin"
Edit your ~/.bash_profile to add the following line:
$ export GOPATH=$HOME/work
Save and exit your editor. Then, source your ~/.bash_profile
$ source ~/.bash_profile
Note: Set the GOBIN path to generate a binary file when go install is run
$ export GOBIN=$HOME/work/bin
This script will help you switch Gopaths. https://github.com/buffonomics/goswitch
You can use the "export" solution just like what other guys have suggested. I'd like to provide you with another solution for permanent convenience: you can use any path as GOPATH when running Go commands.
Firstly, you need to download a small tool named gost : https://github.com/byte16/gost/releases . If you use ubuntu, you can download the linux version(https://github.com/byte16/gost/releases/download/v0.1.0/gost_linux_amd64.tar.gz).
Then you need to run the commands below to unpack it :
$ cd /path/to/your/download/directory
$ tar -xvf gost_linux_amd64.tar.gz
You would get an executable gost. You can move it to /usr/local/bin for convenient use:
$ sudo mv gost /usr/local/bin
Run the command below to add the path you want to use as GOPATH into the pathspace gost maintains. It is required to give the path a name which you would use later.
$ gost add foo /home/foobar/bar # 'foo' is the name and '/home/foobar/bar' is the path
Run any Go command you want in the format:
gost goCommand [-p {pathName}] -- [goFlags...] [goArgs...]
For example, you want to run go get github.com/go-sql-driver/mysql with /home/foobar/bar as the GOPATH, just do it as below:
$ gost get -p foo -- github.com/go-sql-driver/mysql # 'foo' is the name you give to the path above.
It would help you to set the GOPATH and run the command. But remember that you have added the path into gost's pathspace. If you are under any level of subdirectories of /home/foobar/bar, you can even just run the command below which would do the same thing for short :
$ gost get -- github.com/go-sql-driver/mysql
gost is a Simple Tool of Go which can help you to manage GOPATHs and run Go commands. For more details about how to use it to run other Go commands, you can just run gost help goCmdName. For example you want to know more about install, just type words below in:
$ gost help install
You can also find more details in the README of the project: https://github.com/byte16/gost/blob/master/README.md
You have to update the PATH based on the terminal(bash or zsh) which you use.
Open the shell script file of the terminal i.e ~/.bashrc or ~/.zshrc in an editor
vi ~/.zshrc
(or)
code ~/.zshrc
Update the below GOPATH if already found or add the below line.
export GOPATH=$HOME/go:/$HOME/projects/go
Here you can add one or more paths separated by a semicolon : from different locations of your GO projects on the system to the GOPATH environment variable i.e /path/1:path/2:path/3 etc.
In my case, I have added 2 paths, as shown above, one from the root $HOME/go and the other one from the projects directory :/$HOME/projects/go
As written in the official instructions:
The GOPATH environment variable specifies the location of your workspace. It defaults to a directory named go inside your home directory, so $HOME/go on Unix, $home/go on Plan 9, and %USERPROFILE%\go (usually C:\Users\YourName\go) on Windows. If you would like to work in a different location, you will need to set GOPATH to the path to that directory. (Another common setup is to set GOPATH=$HOME.) Note that GOPATH must not be the same path as your Go installation.
So for example, if you are coding in Jetbrains Webstorm (using the Go plugin), you might want to set GOPATH as /Users/<user>/WebstormProjects.
In simpler words, set it to wherever you want your Go projects to reside.

How to set the environmental variable LD_LIBRARY_PATH in linux

I have first executed the command: export LD_LIBRARY_PATH=/usr/local/lib
Then I have opened .bash_profile file: vi ~/.bash_profile.
In this file, I put:
LD_LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH
Then if the terminal is closed and restarted, typing echo $LD_LIBRARY_PATH displays no result.
How to set the path permanently?
You should add more details about your distribution, for example under Ubuntu the right way to do this is to add a custom .conf file to /etc/ld.so.conf.d, for example
sudo gedit /etc/ld.so.conf.d/randomLibs.conf
inside the file you are supposed to write the complete path to the directory that contains all the libraries that you wish to add to the system, for example
/home/linux/myLocalLibs
remember to add only the path to the dir, not the full path for the file, all the libs inside that path will be automatically indexed.
Save and run sudo ldconfig to update the system with this libs.
Keep the previous path, don't overwrite it:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/custom/path/
You can add it to your ~/.bashrc:
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/custom/path/' >> ~/.bashrc
Add
LD_LIBRARY_PATH="/path/you/want1:/path/you/want/2"
to /etc/environment
See the Ubuntu Documentation.
CORRECTION: I should take my own advice and actually read the documentation. It says that this does not apply to LD_LIBRARY_PATH: Since Ubuntu 9.04 Jaunty Jackalope, LD_LIBRARY_PATH cannot be set in $HOME/.profile, /etc/profile, nor /etc/environment files. You must use /etc/ld.so.conf.d/.conf configuration files.* So user1824407's answer is spot on.
Alternatively you can execute program with specified library dir:
/lib/ld-linux.so.2 --library-path PATH EXECUTABLE
Read more here.
The file .bash_profile is only executed by login shells. You may need to put it in ~/.bashrc, or simply logout and login again.
For some reason no one has mentioned the fact that the bashrc needs to be re-sourced after editing. You can either log out and log back in (like mentioned above) but you can also use the commands: source ~/.bashrc or . ~/.bashrc.
Put export LD_LIBRARY_PATH=/usr/local/lib in ~/.bashrc [preferably towards end of script to avoid any overrides in between, Default ~/.bashrc comes with many if-else statements]
Post that whenever you open a new terminal/konsole, LD_LIBRARY_PATH will be reflected
Go to the home folder and edit .profile
Place the following line at the end
export LD_LIBRARY_PATH=<your path>
Save and Exit.
Execute this command
sudo ldconfig
You could try adding a custom script, say myenv_vars.sh in /etc/profile.d.
cd /etc/profile.d
sudo touch myenv_vars.sh
sudo gedit myenv_vars.sh
Add this to the empty file, and save it.
export LD_LIBRARY_PATH=/usr/local/lib
Logout and login, LD_LIBRARY_PATH will have been set permanently.
I do the following in Mint 15 through 17, also works on ubuntu server 12.04 and above:
sudo vi /etc/bash.bashrc
scroll to the bottom, and add:
export LD_LIBRARY_PATH=.
All users have the environment variable added.
In Ubuntu 20.04 Linux this is just not obvious and straight forward as it should be.
I will attempt to make it simple for anyone who is pulling out their hair just like I was with my Ubuntu 20.04.3 Linux.
Start by identifying the path where your library files' folder is located. In my case, the *.so files that I was working with were located in a folder called libs and this folder's path in my Ubuntu box is /usr/lib
So now I want to add the path /usr/lib to LD_LIBRARY_PATH such that when I run echo $LD_LIBRARY_PATH in my Ubuntu terminal I will be able to see the path /usr/lib echoed as shown below;
joseph$ echo $LD_LIBRARY_PATH
:/usr/lib
Here are the steps I used
Open terminal in Ubuntu 20.04 Linux box
Change path to /etc/ld.so.conf.d/ by running cd /etc/ld.so.conf.d/
Create a file with a *.conf extension at the end with a text editor
like e.g. vim or gedit in my case I created it as follows sudo gedit my_project_libs.conf
Inside the .conf file that I created named my_project_libs.conf
I added the path to my libs by adding this line export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib
Thereafter, I then run gedit ~/.bash_profile to open the
~/.bash_profile file so that I can add inside it this line export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib which includes the path to the folder with my libraries /usr/lib that I want
included in LD_LIBRARY_PATH
I also ran gedit ~/.bashrc to open the
~/.bashrc file so that I can add inside it this line export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib which includes the path to the folder with my libraries /usr/lib that I want
included in LD_LIBRARY_PATH
When you are done adding the line in step 5, save and close.
In your terminal, type the following sudo ldconfig and press
enter on your keyboard.
Close all your open terminals that you were using then open a new terminal session and run echo $LD_LIBRARY_PATH If you see the path you added is echoed back, you did it right.
In my case, this is what I see :/usr/lib when I run echo $LD_LIBRARY_PATH in my newly opened Ubuntu terminal session
joseph$ echo $LD_LIBRARY_PATH
:/usr/lib
That's how I got it to work for me in my Ubuntu 20.04.3 Linux box.
Everyone seems to be missing the forest for the trees.
The real answer is that '~/.bash_profile' is by default only sourced for LOGIN SHELLS.
The bash config file you are probably looking for if you are starting and closing terminals from your desktop GUI is '~/.bashrc', which is the file sourced by default when starting interactive, non-login shells.
https://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc

Resources